optimization.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const {ESBuildMinifyPlugin} = require('esbuild-loader');
  2. const isProduction = process.env.NODE_ENV === 'production';
  3. const optimization = {
  4. minimize: isProduction,
  5. minimizer: [
  6. new ESBuildMinifyPlugin({
  7. css: true,
  8. legalComments: 'none',
  9. }),
  10. ],
  11. runtimeChunk: {
  12. name: entrypoint => `runtime~${entrypoint.name}`,
  13. },
  14. splitChunks: {
  15. chunks: 'async',
  16. minSize: 20000,
  17. minRemainingSize: 0,
  18. minChunks: 1,
  19. maxAsyncRequests: 30,
  20. maxInitialRequests: 30,
  21. enforceSizeThreshold: 50000,
  22. cacheGroups: {
  23. defaultVendors: {
  24. test: /[\\/]node_modules[\\/]/,
  25. priority: -10,
  26. reuseExistingChunk: true,
  27. },
  28. default: {
  29. minChunks: 2,
  30. priority: -20,
  31. reuseExistingChunk: true,
  32. },
  33. reactVendors: {
  34. name: 'react-vendors',
  35. chunks: 'all',
  36. test: /[\\/]node_modules[\\/](react|react-dom|react-dom-router|@remix-run|scheduler)/,
  37. priority: 10,
  38. reuseExistingChunk: true,
  39. },
  40. lottieVendors: {
  41. name: 'lottie',
  42. chunks: 'all',
  43. test: /[\\/]node_modules[\\/](lottie)/,
  44. priority: 10,
  45. reuseExistingChunk: true,
  46. },
  47. },
  48. },
  49. };
  50. module.exports = optimization;