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.conf");
  const CopyWebpackPlugin = require("copy-webpack-plugin");
  const HtmlWebpackPlugin = require("html-webpack-plugin");
  const OptimizeCSSPlugin = require("optimize-css-assets-webpack-plugin");
  const ImageminPlugin = require("imagemin-webpack-plugin").default;
  const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  
  const env =
    process.env.NODE_ENV === "testing" ?
    require("../config/test.env") :
    require("../config/prod.env");
  const envVariables = utils.parseEnvVariables(env);
  
  let webpackConfig = merge(baseWebpackConfig, {
    mode: "development",
    module: {
      rules: utils.styleLoaders({
        sourceMap: config.build.productionSourceMap,
        extract: true,
        usePostCSS: true
      })
    },
    devtool: config.build.productionSourceMap ? config.build.devtool : false,
    output: {
      path: config.build.assetsRoot,
      filename: utils.assetsPath("js/[name].[chunkhash:8].js"),
      chunkFilename: utils.assetsPath("js/[id].[chunkhash:8].js")
    },
    optimization: {
      runtimeChunk: {
        name: "manifest"
      },
      splitChunks: {
        cacheGroups: {
          commons: {
            test: /[\\/]node_modules[\\/]/,
            name: "vendor",
            chunks: "all"
          }
        }
      }
    },
    plugins: [
      new webpack.DefinePlugin(envVariables),
      // extract css into its own file
      // new ExtractTextPlugin({
      //   filename: utils.assetsPath('css/[name].[contenthash].css'),
      //   // set the following option to `true` if you want to extract CSS from
      //   // codesplit chunks into this main css file as well.
      //   // This will result in *all* of your app's CSS being loaded upfront.
      //   allChunks: false,
      // }),
      // 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: process.env.NODE_ENV === "testing" ? "index.html" : config.build.index,
        template: "public/index.html",
        inject: true,
        minify: {
          removeComments: true,
          collapseWhitespace: true,
          removeAttributeQuotes: true,
          minifyCSS: true,
          minifyJS: true
          // more options:
          // https://github.com/kangax/html-minifier#options-quick-reference
        },
        // necessary to consistently work with multiple chunks via CommonsChunkPlugin
        chunksSortMode: "dependency"
      }),
      // keep module.id stable when vender modules does not change
      new webpack.HashedModuleIdsPlugin(),
      // enable scope hoisting
      new webpack.optimize.ModuleConcatenationPlugin(),
      // 不copy
      // new CopyWebpackPlugin([{
      //   from: path.resolve(__dirname, '../static'),
      //   to: config.build.assetsSubDirectory,
      //   ignore: ['.*'],
      // }, ]),
      new ImageminPlugin({
        test: /\.(jpe?g|png|gif|svg)$/i,
        pngquant: {
          quality: "100"
        }
      }),
      new BundleAnalyzerPlugin({
        analyzerMode: 'static',
        reportFilename: 'BundleReport.html',
        logLevel: 'info'
      })
    ]
  });
  
  if (config.build.productionGzip) {
    const CompressionWebpackPlugin = require("compression-webpack-plugin");
  
    webpackConfig.plugins.push(
      new CompressionWebpackPlugin({
        asset: "[path].gz[query]",
        algorithm: "gzip",
        test: new RegExp(
          "\\.(" + config.build.productionGzipExtensions.join("|") + ")$"
        ),
        threshold: 10240,
        minRatio: 0.8
      })
    );
  }
  
  if (config.build.bundleAnalyzerReport) {
    const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
      .BundleAnalyzerPlugin;
    webpackConfig.plugins.push(
      new BundleAnalyzerPlugin({
        analyzerMode: "static",
        openAnalyzer: false,
        generateStatsFile: true
      })
    );
  }
  
  module.exports = webpackConfig;
  