|
@@ -22,46 +22,107 @@ function getModulePackageName(module: { context: string }) {
|
|
|
}
|
|
|
|
|
|
const webpackPlugin = (config: IWebpackChainConfig) => {
|
|
|
- // optimize chunks
|
|
|
- config.optimization
|
|
|
- // share the same chunks across different modules
|
|
|
- .runtimeChunk(false)
|
|
|
- .splitChunks({
|
|
|
- chunks: 'async',
|
|
|
- name: 'vendors',
|
|
|
- maxInitialRequests: Infinity,
|
|
|
- minSize: 30000,
|
|
|
- minChunks: 3,
|
|
|
- automaticNameDelimiter: '.',
|
|
|
- cacheGroups: {
|
|
|
- vendors: {
|
|
|
- test: (module: { context: string }) => {
|
|
|
- const packageName = getModulePackageName(module) || '';
|
|
|
- if (packageName) {
|
|
|
- return [
|
|
|
- 'bizcharts',
|
|
|
- 'gg-editor',
|
|
|
- 'g6',
|
|
|
- '@antv',
|
|
|
- 'l7',
|
|
|
- 'gg-editor-core',
|
|
|
- 'bizcharts-plugin-slider',
|
|
|
- ].includes(packageName);
|
|
|
- }
|
|
|
- return false;
|
|
|
+ config.merge({
|
|
|
+ optimization: {
|
|
|
+ minimize: true,
|
|
|
+ splitChunks: {
|
|
|
+ chunks: 'async',
|
|
|
+ minSize: 30000,
|
|
|
+ minChunks: 2,
|
|
|
+ automaticNameDelimiter: '.',
|
|
|
+ cacheGroups: {
|
|
|
+ vendor: {
|
|
|
+ name: 'vendors',
|
|
|
+ test: /^.*node_modules[\\/](?!ag-grid-|lodash|wangeditor|react-virtualized|rc-select|rc-drawer|rc-time-picker|rc-tree|rc-table|rc-calendar|antd).*$/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: 10,
|
|
|
},
|
|
|
- name(module: { context: string }) {
|
|
|
- const packageName = getModulePackageName(module);
|
|
|
- if (packageName) {
|
|
|
- if (['bizcharts', '@antv_data-set'].indexOf(packageName) >= 0) {
|
|
|
- return 'viz'; // visualization package
|
|
|
- }
|
|
|
- }
|
|
|
- return 'misc';
|
|
|
+ virtualized: {
|
|
|
+ name: "virtualized",
|
|
|
+ test: /[\\/]node_modules[\\/]react-virtualized/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: 10
|
|
|
},
|
|
|
- },
|
|
|
- },
|
|
|
- });
|
|
|
+ rcselect: {
|
|
|
+ name: "rc-select",
|
|
|
+ test: /[\\/]node_modules[\\/]rc-select/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: 10
|
|
|
+ },
|
|
|
+ rcdrawer: {
|
|
|
+ name: "rcdrawer",
|
|
|
+ test: /[\\/]node_modules[\\/]rc-drawer/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: 10
|
|
|
+ },
|
|
|
+ rctimepicker: {
|
|
|
+ name: "rctimepicker",
|
|
|
+ test: /[\\/]node_modules[\\/]rc-time-picker/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: 10
|
|
|
+ },
|
|
|
+ ag: {
|
|
|
+ name: "ag",
|
|
|
+ test: /[\\/]node_modules[\\/]ag-grid-/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: 10
|
|
|
+ },
|
|
|
+ antd: {
|
|
|
+ name: "antd",
|
|
|
+ test: /[\\/]node_modules[\\/]antd[\\/]/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: 9
|
|
|
+ },
|
|
|
+ rctree: {
|
|
|
+ name: "rctree",
|
|
|
+ test: /[\\/]node_modules[\\/]rc-tree/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: -1
|
|
|
+ },
|
|
|
+ rccalendar: {
|
|
|
+ name: "rccalendar",
|
|
|
+ test: /[\\/]node_modules[\\/]rc-calendar[\\/]/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: -1
|
|
|
+ },
|
|
|
+ rctable: {
|
|
|
+ name: "rctable",
|
|
|
+ test: /[\\/]node_modules[\\/]rc-table[\\/]es[\\/]/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: -1
|
|
|
+ },
|
|
|
+ wang: {
|
|
|
+ name: "wang",
|
|
|
+ test: /[\\/]node_modules[\\/]wangeditor[\\/]/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: -1
|
|
|
+ },
|
|
|
+ lodash: {
|
|
|
+ name: "lodash",
|
|
|
+ test: /[\\/]node_modules[\\/]lodash[\\/]/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: -2
|
|
|
+ },
|
|
|
+ bizcharts: {
|
|
|
+ name: "bizcharts",
|
|
|
+ test: /[\\/]node_modules[\\/]bizcharts[\\/]/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: 10
|
|
|
+ },
|
|
|
+ xlsx: {
|
|
|
+ name: "xlsx",
|
|
|
+ test: /[\\/]node_modules[\\/]xlsx[\\/]/,
|
|
|
+ chunks: "async",
|
|
|
+ priority: 10
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //过滤掉momnet的那些不使用的国际化文件
|
|
|
+ config.plugin("replace").use(require("webpack").ContextReplacementPlugin).tap(() => {
|
|
|
+ return [/moment[/\\]locale$/, /zh-cn/];
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
export default webpackPlugin;
|