plugin.config.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import * as IWebpackChainConfig from 'webpack-chain';
  2. const webpackPlugin = (config: IWebpackChainConfig) => {
  3. config.merge({
  4. optimization: {
  5. minimize: true,
  6. splitChunks: {
  7. chunks: 'async',
  8. minSize: 30000,
  9. minChunks: 2,
  10. automaticNameDelimiter: '.',
  11. cacheGroups: {
  12. vendor: {
  13. name: 'vendors',
  14. test: /^.*node_modules[\\/](?!ag-grid-|lodash|wangeditor|react-virtualized|rc-select|rc-drawer|rc-time-picker|rc-tree|rc-table|rc-calendar|antd).*$/,
  15. chunks: "all",
  16. priority: 10,
  17. },
  18. virtualized: {
  19. name: "virtualized",
  20. test: /[\\/]node_modules[\\/]react-virtualized/,
  21. chunks: "all",
  22. priority: 10
  23. },
  24. rcselect: {
  25. name: "rc-select",
  26. test: /[\\/]node_modules[\\/]rc-select/,
  27. chunks: "all",
  28. priority: 10
  29. },
  30. rcdrawer: {
  31. name: "rcdrawer",
  32. test: /[\\/]node_modules[\\/]rc-drawer/,
  33. chunks: "all",
  34. priority: 10
  35. },
  36. rctimepicker: {
  37. name: "rctimepicker",
  38. test: /[\\/]node_modules[\\/]rc-time-picker/,
  39. chunks: "all",
  40. priority: 10
  41. },
  42. ag: {
  43. name: "ag",
  44. test: /[\\/]node_modules[\\/]ag-grid-/,
  45. chunks: "all",
  46. priority: 10
  47. },
  48. antd: {
  49. name: "antd",
  50. test: /[\\/]node_modules[\\/]antd[\\/]/,
  51. chunks: "all",
  52. priority: 9
  53. },
  54. rctree: {
  55. name: "rctree",
  56. test: /[\\/]node_modules[\\/]rc-tree/,
  57. chunks: "all",
  58. priority: -1
  59. },
  60. rccalendar: {
  61. name: "rccalendar",
  62. test: /[\\/]node_modules[\\/]rc-calendar[\\/]/,
  63. chunks: "all",
  64. priority: -1
  65. },
  66. rctable: {
  67. name: "rctable",
  68. test: /[\\/]node_modules[\\/]rc-table[\\/]es[\\/]/,
  69. chunks: "all",
  70. priority: -1
  71. },
  72. wang: {
  73. name: "wang",
  74. test: /[\\/]node_modules[\\/]wangeditor[\\/]/,
  75. chunks: "all",
  76. priority: -1
  77. },
  78. lodash: {
  79. name: "lodash",
  80. test: /[\\/]node_modules[\\/]lodash[\\/]/,
  81. chunks: "all",
  82. priority: -2
  83. },
  84. bizcharts: {
  85. name: "bizcharts",
  86. test: /[\\/]node_modules[\\/]bizcharts[\\/]/,
  87. chunks: "all",
  88. priority: 10
  89. },
  90. xlsx: {
  91. name: "xlsx",
  92. test: /[\\/]node_modules[\\/]xlsx[\\/]/,
  93. chunks: "async",
  94. priority: 10
  95. }
  96. }
  97. }
  98. }
  99. });
  100. //过滤掉momnet的那些不使用的国际化文件
  101. config.plugin("replace").use(require("webpack").ContextReplacementPlugin).tap(() => {
  102. return [/moment[/\\]locale$/, /zh-cn/];
  103. });
  104. };
  105. export default webpackPlugin;