|
|
@@ -4,6 +4,25 @@ import MergeLessPlugin from 'antd-pro-merge-less';
|
|
|
import AntDesignThemePlugin from 'antd-theme-webpack-plugin';
|
|
|
import path from 'path';
|
|
|
|
|
|
+function getModulePackageName(module) {
|
|
|
+ if (!module.context) return null;
|
|
|
+
|
|
|
+ const nodeModulesPath = path.join(__dirname, '../node_modules/');
|
|
|
+ if (module.context.substring(0, nodeModulesPath.length) !== nodeModulesPath) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ const moduleRelativePath = module.context.substring(nodeModulesPath.length);
|
|
|
+ const [moduleDirName] = moduleRelativePath.split(path.sep);
|
|
|
+ let packageName = moduleDirName;
|
|
|
+ // handle tree shaking
|
|
|
+ if (packageName.match('^_')) {
|
|
|
+ // eslint-disable-next-line prefer-destructuring
|
|
|
+ packageName = packageName.match(/^_(@?[^@]+)/)[1];
|
|
|
+ }
|
|
|
+ return packageName;
|
|
|
+}
|
|
|
+
|
|
|
export default config => {
|
|
|
// pro 和 开发环境再添加这个插件
|
|
|
if (process.env.APP_TYPE === 'site' || process.env.NODE_ENV !== 'production') {
|
|
|
@@ -30,4 +49,32 @@ export default config => {
|
|
|
},
|
|
|
]);
|
|
|
}
|
|
|
+ // optimize chunks
|
|
|
+ config.optimization
|
|
|
+ .runtimeChunk(false) // share the same chunks across different modules
|
|
|
+ .splitChunks({
|
|
|
+ chunks: 'async',
|
|
|
+ name: 'vendors',
|
|
|
+ maxInitialRequests: Infinity,
|
|
|
+ minSize: 0,
|
|
|
+ cacheGroups: {
|
|
|
+ vendors: {
|
|
|
+ test: module => {
|
|
|
+ const packageName = getModulePackageName(module);
|
|
|
+ if (packageName) {
|
|
|
+ return ['bizcharts', '@antv_data-set'].indexOf(packageName) >= 0;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ name(module) {
|
|
|
+ const packageName = getModulePackageName(module);
|
|
|
+
|
|
|
+ if (['bizcharts', '@antv_data-set'].indexOf(packageName) >= 0) {
|
|
|
+ return 'viz'; // visualization package
|
|
|
+ }
|
|
|
+ return 'misc';
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ });
|
|
|
};
|