text: /*
   * @Author: your name
   * @Date: 2020-03-23 17:22:08
   * @LastEditTime: 2020-03-24 17:41:43
   * @LastEditors: your name
   * @Description: In User Settings Edit
   * @FilePath: /webpack_learn/10_demo/build-webpack/lib/webpack.prod.js
   */
  const cssnano = require('cssnano');
  const merge = require('webpack-merge');
  const HtmlWebpackExternalsPlugin = require('html-webpack-externals-plugin');
  const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  const baseConfig = require('./webpack.base');
  
  const prodConfig = {
    mode: 'production',
    plugins: [
      new OptimizeCSSAssetsPlugin({
        assetNameRegExp: /\.css$/g,
        cssProcessor: cssnano,
      }),
      new HtmlWebpackExternalsPlugin({
        externals: [
          {
            module: 'react',
            entry: 'https://11.url.cn/now/lib/16.2.0/react.min.js',
            global: 'React',
          },
          {
            module: 'react-dom',
            entry: 'https://11.url.cn/now/lib/16.2.0/react-dom.min.js',
            global: 'ReactDOM',
          },
        ],
      }),
    ],
    optimization: {
      splitChunks: {
        minSize: 0,
        cacheGroups: {
          commons: {
            name: 'vendors',
            chunks: 'all',
            minChunks: 2,
          },
        },
      },
    },
  };
  
  module.exports = merge(baseConfig, prodConfig);