123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- /* eslint-disable camelcase */
- const TerserPlugin = require('terser-webpack-plugin');
- const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
- const isProduction = process.env.NODE_ENV === 'production';
- const optimization = {
- minimize: isProduction,
- minimizer: [
- new TerserPlugin({
- terserOptions: {
- parse: {
- // We want terser to parse ecma 8 code. However, we don't want it
- // to apply any minification steps that turns valid ecma 5 code
- // into invalid ecma 5 code. This is why the 'compress' and 'output'
- // sections only apply transformations that are ecma 5 safe
- // https://github.com/facebook/create-react-app/pull/4234
- ecma: 8,
- },
- compress: {
- ecma: 5,
- warnings: false,
- // Disabled because of an issue with Uglify breaking seemingly valid code:
- // https://github.com/facebook/create-react-app/issues/2376
- // Pending further investigation:
- // https://github.com/mishoo/UglifyJS2/issues/2011
- comparisons: false,
- // Disabled because of an issue with Terser breaking valid code:
- // https://github.com/facebook/create-react-app/issues/5250
- // Pending further investigation:
- // https://github.com/terser-js/terser/issues/120
- inline: 2,
- },
- mangle: {
- safari10: true,
- },
- // Added for profiling in devtools
- keep_classnames: isProduction,
- keep_fnames: isProduction,
- output: {
- ecma: 5,
- comments: false,
- // Turned on because emoji and regex is not minified properly using default
- // https://github.com/facebook/create-react-app/issues/2488
- ascii_only: true,
- },
- },
- }),
- new CssMinimizerPlugin(),
- ],
- runtimeChunk: {
- name: entrypoint => `runtime~${entrypoint.name}`,
- },
- splitChunks: {
- chunks: 'async',
- minSize: 20000,
- minRemainingSize: 0,
- minChunks: 1,
- maxAsyncRequests: 30,
- maxInitialRequests: 30,
- enforceSizeThreshold: 50000,
- cacheGroups: {
- defaultVendors: {
- test: /[\\/]node_modules[\\/]/,
- priority: -10,
- reuseExistingChunk: true,
- },
- default: {
- minChunks: 2,
- priority: -20,
- reuseExistingChunk: true,
- },
- reactVendors: {
- name: 'react-vendors',
- chunks: 'all',
- test: /[\\/]node_modules[\\/](react|react-dom|react-dom-router|@remix-run|scheduler)/,
- priority: 10,
- reuseExistingChunk: true,
- },
- lottieVendors: {
- name: 'lottie',
- chunks: 'all',
- test: /[\\/]node_modules[\\/](lottie)/,
- priority: 10,
- reuseExistingChunk: true,
- },
- antdVendors: {
- name: 'antd',
- chunks: 'all',
- test: /[\\/]node_modules[\\/](antd)/,
- priority: 10,
- reuseExistingChunk: true,
- },
- recharsVendors: {
- name: 'rechars',
- chunks: 'all',
- test: /[\\/]node_modules[\\/](recharts)/,
- priority: 10,
- reuseExistingChunk: true,
- },
- lodash: {
- name: 'lodash',
- chunks: 'all',
- test: /[\\/]node_modules[\\/](lodash)/,
- priority: 10,
- reuseExistingChunk: true,
- },
- },
- },
- };
- module.exports = optimization;
|