text: 'use strict'
  
  const path = require('path')
  const utils = require('./utils')
  const webpack = require('webpack')
  const config = require('../config')
  const { merge } = require('webpack-merge')
  const baseWebpackConfig = require('./webpack.base.config')
  const CopyWebpackPlugin = require('copy-webpack-plugin')
  const HtmlWebpackPlugin = require('html-webpack-plugin')
  const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  const env = require('../config/prod.env')
  
  const webpackConfig = merge(baseWebpackConfig, {
    mode: 'production',
    devtool: config.build.productionSourceMap ? config.build.devtool : false,
    output: {
      path: config.build.assetsRoot,
      filename: utils.assetsPath('js/[name].[contenthash].js'),
      chunkFilename: utils.assetsPath('js/[id].[contenthash].js'),
    },
    plugins: [
      // http://vuejs.github.io/vue-loader/en/workflow/production.html
      new webpack.DefinePlugin({
        'process.env': env,
      }),
      // extract css into its own file
      new MiniCssExtractPlugin({
        filename: utils.assetsPath('css/[name].[hash].css'),
        // Setting the following option to `false` will not extract CSS from codesplit chunks.
        // Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack.
        // It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`,
        // increasing file size: https://github.com/vuejs-templates/webpack/issues/1110
      }),
      // Compress extracted CSS. We are using this plugin so that possible
      // duplicated CSS from different components can be deduped.
      // new OptimizeCSSPlugin({
      //   cssProcessorOptions: config.build.productionSourceMap
      //     ? { safe: true, map: { inline: false } }
      //     : { safe: true },
      // }),
      // generate dist index.html with correct asset hash for caching.
      // you can customize output by editing /index.html
      // see https://github.com/ampedandwired/html-webpack-plugin
      new HtmlWebpackPlugin({
        filename: config.build.index,
        template: 'index.html',
        inject: true,
        minify: true,
        // necessary to consistently work with multiple chunks via CommonsChunkPlugin
        chunksSortMode: 'auto',
      }),
      // enable scope hoisting
      new webpack.optimize.ModuleConcatenationPlugin(),
      // copy custom static assets
      new CopyWebpackPlugin({
        patterns: [
          {
            from: path.resolve(__dirname, '../static'),
            to: config.build.assetsRoot,
          },
        ],
      }),
    ],
    optimization: {
      moduleIds: 'named',
    },
  })
  
  if (config.build.productionGzip) {
    const CompressionWebpackPlugin = require('compression-webpack-plugin')
  
    webpackConfig.plugins.push(
      new CompressionWebpackPlugin({
        filename: '[path].gz[query]',
        algorithm: 'gzip',
        test: new RegExp(
          `\\.(${config.build.productionGzipExtensions.join('|')})$`
        ),
        threshold: 10240,
        minRatio: 0.8,
      })
    )
  }
  
  module.exports = webpackConfig
  