optimization.js 1.2 KB
Newer Older
ada committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
const constants = require('./constants')
const config = require('./config')
const TerserPlugin = require('terser-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')

module.exports =
    constants.APP_ENV === 'dev'
        ? {}
        : {
              runtimeChunk: {
                  name: 'manifest'
              },
              splitChunks: {
                  cacheGroups: {
                      default: false,
                      commons: {
                          test: /[\\/]node_modules[\\/]/,
                          name: 'split-vendor',
                          chunks: 'all'
                      }
                  }
              },
              minimizer: [
                  new TerserPlugin({
                      cache: true,
                      parallel: true,
                      sourceMap: Boolean(config.sourceMap)
                  }),
                  new OptimizeCSSAssetsPlugin({
                      cssProcessor: require('cssnano'),
                      cssProcessorOptions: {
                          reduceIdents: false,
                          autoprefixer: false
                      }
                  })
              ]
          }