plugin.config.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. // Change theme plugin
  2. import MergeLessPlugin from 'antd-pro-merge-less';
  3. import AntDesignThemePlugin from 'antd-theme-webpack-plugin';
  4. import path from 'path';
  5. const CompressionWebpackPlugin = require('compression-webpack-plugin');
  6. const prodGzipList = ['js', 'css'];
  7. export default config => {
  8. // pro 和 开发环境再添加这个插件
  9. if (process.env.APP_TYPE === 'site' || process.env.NODE_ENV !== 'production') {
  10. // 将所有 less 合并为一个供 themePlugin使用
  11. const outFile = path.join(__dirname, '../.temp/ant-design-pro.less');
  12. const stylesDir = path.join(__dirname, '../src/');
  13. config.plugin('merge-less').use(MergeLessPlugin, [
  14. {
  15. stylesDir,
  16. outFile,
  17. },
  18. ]);
  19. config.plugin('ant-design-theme').use(AntDesignThemePlugin, [
  20. {
  21. antDir: path.join(__dirname, '../node_modules/antd'),
  22. stylesDir,
  23. varFile: path.join(__dirname, '../node_modules/antd/lib/style/themes/default.less'),
  24. mainLessFile: outFile, // themeVariables: ['@primary-color'],
  25. indexFileName: 'index.html',
  26. generateOne: true,
  27. lessUrl: 'https://gw.alipayobjects.com/os/lib/less.js/3.8.1/less.min.js',
  28. },
  29. ]);
  30. }
  31. if (process.env.APP_TYPE !== 'site' || process.env.NODE_ENV !== 'development') {
  32. config.merge({
  33. optimization: {
  34. minimize: true,
  35. splitChunks: {
  36. chunks: 'async',
  37. // chunks(chunk) {
  38. // // exclude `my-excluded-chunk`
  39. // return chunk.name !== 'my-excluded-chunk';
  40. // },
  41. minSize: 20000, //生成块的最小大小(以字节为单位)1024字节=1KB。
  42. minChunks: 1, //拆分前必须共享模块的最小块数。
  43. maxInitialRequests: 30, //入口点的最大并行请求数。
  44. automaticNameDelimiter: '.',
  45. cacheGroups: {
  46. vendor: {
  47. name: 'vendors',
  48. test: /^.*node_modules[\\/](?!ag-grid-|lodash|wangeditor|react-virtualized|rc-drawer|rc-time-picker|rc-tree|echarts|echarts-gl|xlsx|@ant-design|antd|ali-oss).*$/,
  49. priority: -10,
  50. enforce: true,
  51. },
  52. virtualized: {
  53. name: "virtualized",
  54. test: /[\\/]node_modules[\\/]react-virtualized/,
  55. priority: 10,
  56. },
  57. antd: {
  58. name: "antd",
  59. test: /[\\/]node_modules[\\/]antd[\\/]/,
  60. priority: 9,
  61. },
  62. // antv: {
  63. // name: "@antv",
  64. // test: /[\\/]node_modules[\\/]@antv[\\/]/,
  65. // priority: 9,
  66. // },
  67. echarts: { // 1.27MB
  68. name: "echarts",
  69. test: /[\\/]node_modules[\\/](echarts|echarts-gl)[\\/]/,
  70. priority: 10,
  71. enforce: true,
  72. },
  73. bizcharts: {
  74. name: "bizcharts",
  75. test: /[\\/]node_modules[\\/]bizcharts[\\/]/,
  76. chunks: "all",
  77. priority: 10
  78. },
  79. hlsJs: {
  80. name: "hlsJs",
  81. test: /[\\/]node_modules[\\/]hls.js[\\/]/,
  82. chunks: "all",
  83. priority: 10
  84. },
  85. // moment: {
  86. // name: "moment",
  87. // test: /[\\/]node_modules[\\/]moment[\\/]/,
  88. // chunks: "all",
  89. // priority: 10
  90. // },
  91. fileManage: {
  92. name: "fileManage",
  93. test: /[\\/]node_modules[\\/]@opuscapita[\\/]/,
  94. chunks: "all",
  95. priority: 10
  96. },
  97. pdfJs: {
  98. name: "pdfjs-dist",
  99. test: /[\\/]node_modules[\\/]pdfjs-dist[\\/]/,
  100. chunks: "all",
  101. priority: 10
  102. },
  103. ggEditor: {
  104. name: "ggEditor",
  105. test: /[\\/]node_modules[\\/]gg-editor-core[\\/]/,
  106. chunks: "all",
  107. priority: 10
  108. },
  109. // zrender: {
  110. // name: "zrender",
  111. // test: /[\\/]node_modules[\\/]zrender[\\/]/,
  112. // chunks: "all",
  113. // priority: 10
  114. // },
  115. swiper: {
  116. name: "swiper",
  117. test: /[\\/]node_modules[\\/]swiper[\\/]/,
  118. chunks: "all",
  119. priority: 10
  120. },
  121. flv: {
  122. name: "flv",
  123. test: /[\\/]node_modules[\\/]flv.js[\\/]/,
  124. chunks: "all",
  125. priority: 10
  126. },
  127. xlsx: {
  128. name: "xlsx",
  129. test: /[\\/]node_modules[\\/]xlsx[\\/]/,
  130. chunks: "async",
  131. priority: 10
  132. },
  133. // rctree: {
  134. // name: "rctree",
  135. // test: /[\\/]node_modules[\\/]rc-tree/,
  136. // chunks: "all",
  137. // priority: -1
  138. // },
  139. // rccalendar: {
  140. // name: "rccalendar",
  141. // test: /[\\/]node_modules[\\/]rc-calendar[\\/]/,
  142. // chunks: "all",
  143. // priority: -1
  144. // },
  145. wang: {
  146. name: "wang",
  147. test: /[\\/]node_modules[\\/]wangeditor[\\/]/,
  148. chunks: "all",
  149. priority: -1
  150. },
  151. // lodash: {
  152. // name: "lodash",
  153. // test: /[\\/]node_modules[\\/]lodash[\\/]/,
  154. // chunks: "all",
  155. // priority: -2
  156. // },
  157. // rcdrawer: {
  158. // name: "rcdrawer",
  159. // test: /[\\/]node_modules[\\/]rc-drawer/,
  160. // chunks: "all",
  161. // priority: 10
  162. // },
  163. ag: {
  164. name: "ag",
  165. test: /[\\/]node_modules[\\/]ag-grid-/,
  166. chunks: "all",
  167. priority: 10
  168. },
  169. }
  170. },
  171. },
  172. });
  173. }
  174. if (process.env.NODE_ENV === 'production') {
  175. // 生产模式开启
  176. config.plugin('compression-webpack-plugin').use(
  177. new CompressionWebpackPlugin({
  178. // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
  179. algorithm: 'gzip', // 指定生成gzip格式
  180. test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
  181. threshold: 10240, //对超过10k的数据进行压缩
  182. minRatio: 0.6 // 压缩比例,值为0 ~ 1
  183. })
  184. );
  185. }
  186. //过滤掉momnet的那些不使用的国际化文件
  187. config.plugin("replace").use(require("webpack").ContextReplacementPlugin).tap(() => {
  188. return [/moment[/\\]locale$/, /zh-cn/];
  189. });
  190. // config.output.filename = '[name].[contenthash].js'
  191. };