optimization.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. extractComments: false,
  10. terserOptions: {
  11. mangle: {
  12. safari10: true,
  13. },
  14. format: {
  15. comments: false,
  16. },
  17. },
  18. }),
  19. new CssMinimizerPlugin(),
  20. ],
  21. runtimeChunk: {
  22. name: entrypoint => `runtime~${entrypoint.name}`,
  23. },
  24. splitChunks: {
  25. chunks: 'async',
  26. minSize: 20000,
  27. minRemainingSize: 0,
  28. minChunks: 1,
  29. maxAsyncRequests: 30,
  30. maxInitialRequests: 30,
  31. enforceSizeThreshold: 50000,
  32. cacheGroups: {
  33. defaultVendors: {
  34. test: /[\\/]node_modules[\\/]/,
  35. priority: -10,
  36. reuseExistingChunk: true,
  37. },
  38. default: {
  39. minChunks: 2,
  40. priority: -20,
  41. reuseExistingChunk: true,
  42. },
  43. reactVendors: {
  44. name: 'react-vendors',
  45. chunks: 'all',
  46. test: /[\\/]node_modules[\\/](react|react-dom|react-dom-router|@remix-run|scheduler)/,
  47. priority: 10,
  48. reuseExistingChunk: true,
  49. },
  50. lottieVendors: {
  51. name: 'lottie',
  52. chunks: 'all',
  53. test: /[\\/]node_modules[\\/](lottie)/,
  54. priority: 10,
  55. reuseExistingChunk: true,
  56. },
  57. antdVendors: {
  58. name: 'antd',
  59. chunks: 'all',
  60. test: /[\\/]node_modules[\\/](antd)/,
  61. priority: 10,
  62. reuseExistingChunk: true,
  63. },
  64. recharsVendors: {
  65. name: 'rechars',
  66. chunks: 'all',
  67. test: /[\\/]node_modules[\\/](recharts)/,
  68. priority: 10,
  69. reuseExistingChunk: true,
  70. },
  71. lodash: {
  72. name: 'lodash',
  73. chunks: 'all',
  74. test: /[\\/]node_modules[\\/](lodash)/,
  75. priority: 10,
  76. reuseExistingChunk: true,
  77. },
  78. },
  79. },
  80. };
  81. module.exports = optimization;