optimization.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* eslint-disable camelcase */
  2. const TerserPlugin = require('terser-webpack-plugin');
  3. const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
  4. const isProduction = process.env.NODE_ENV === 'production';
  5. const optimization = {
  6. minimize: isProduction,
  7. minimizer: [
  8. new TerserPlugin({
  9. terserOptions: {
  10. parse: {
  11. // We want terser to parse ecma 8 code. However, we don't want it
  12. // to apply any minification steps that turns valid ecma 5 code
  13. // into invalid ecma 5 code. This is why the 'compress' and 'output'
  14. // sections only apply transformations that are ecma 5 safe
  15. // https://github.com/facebook/create-react-app/pull/4234
  16. ecma: 8,
  17. },
  18. compress: {
  19. ecma: 5,
  20. warnings: false,
  21. // Disabled because of an issue with Uglify breaking seemingly valid code:
  22. // https://github.com/facebook/create-react-app/issues/2376
  23. // Pending further investigation:
  24. // https://github.com/mishoo/UglifyJS2/issues/2011
  25. comparisons: false,
  26. // Disabled because of an issue with Terser breaking valid code:
  27. // https://github.com/facebook/create-react-app/issues/5250
  28. // Pending further investigation:
  29. // https://github.com/terser-js/terser/issues/120
  30. inline: 2,
  31. },
  32. mangle: {
  33. safari10: true,
  34. },
  35. // Added for profiling in devtools
  36. keep_classnames: isProduction,
  37. keep_fnames: isProduction,
  38. output: {
  39. ecma: 5,
  40. comments: false,
  41. // Turned on because emoji and regex is not minified properly using default
  42. // https://github.com/facebook/create-react-app/issues/2488
  43. ascii_only: true,
  44. },
  45. },
  46. }),
  47. new CssMinimizerPlugin(),
  48. ],
  49. runtimeChunk: {
  50. name: entrypoint => `runtime~${entrypoint.name}`,
  51. },
  52. splitChunks: {
  53. chunks: 'async',
  54. minSize: 20000,
  55. minRemainingSize: 0,
  56. minChunks: 1,
  57. maxAsyncRequests: 30,
  58. maxInitialRequests: 30,
  59. enforceSizeThreshold: 50000,
  60. cacheGroups: {
  61. defaultVendors: {
  62. test: /[\\/]node_modules[\\/]/,
  63. priority: -10,
  64. reuseExistingChunk: true,
  65. },
  66. default: {
  67. minChunks: 2,
  68. priority: -20,
  69. reuseExistingChunk: true,
  70. },
  71. reactVendors: {
  72. name: 'react-vendors',
  73. chunks: 'all',
  74. test: /[\\/]node_modules[\\/](react|react-dom|react-dom-router|@remix-run|scheduler)/,
  75. priority: 10,
  76. reuseExistingChunk: true,
  77. },
  78. lottieVendors: {
  79. name: 'lottie',
  80. chunks: 'all',
  81. test: /[\\/]node_modules[\\/](lottie)/,
  82. priority: 10,
  83. reuseExistingChunk: true,
  84. },
  85. antdVendors: {
  86. name: 'antd',
  87. chunks: 'all',
  88. test: /[\\/]node_modules[\\/](antd)/,
  89. priority: 10,
  90. reuseExistingChunk: true,
  91. },
  92. recharsVendors: {
  93. name: 'rechars',
  94. chunks: 'all',
  95. test: /[\\/]node_modules[\\/](recharts)/,
  96. priority: 10,
  97. reuseExistingChunk: true,
  98. },
  99. lodash: {
  100. name: 'lodash',
  101. chunks: 'all',
  102. test: /[\\/]node_modules[\\/](lodash)/,
  103. priority: 10,
  104. reuseExistingChunk: true,
  105. },
  106. },
  107. },
  108. };
  109. module.exports = optimization;