build: optimize webpack code split (#10831)

This commit is contained in:
Jesse Yang 2020-09-10 15:11:21 -07:00 committed by GitHub
parent f0545bfe50
commit d80f406239
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 56 additions and 6 deletions

View File

@ -43,6 +43,8 @@ const {
devserverPort = 9000,
measure = false,
analyzeBundle = false,
analyzerPort = 8888,
nameChunks = false,
} = parsedArgs;
const isDevMode = mode !== 'production';
@ -197,13 +199,61 @@ const config = {
sideEffects: true,
splitChunks: {
chunks: 'all',
name: nameChunks,
automaticNameDelimiter: '-',
minChunks: 2,
cacheGroups: {
default: false,
major: {
name: 'vendors-major',
test: /\/node_modules\/(brace|react|react-dom|@superset-ui\/translation|webpack.*|@babel.*)\//,
automaticNamePrefix: 'chunk',
// basic stable dependencies
vendors: {
priority: 50,
name: 'vendors',
test: new RegExp(
`/node_modules/(${[
'abortcontroller-polyfill',
'react',
'react-dom',
'prop-types',
'redux',
'react-redux',
'react-hot-loader',
'react-select',
'react-sortable-hoc',
'react-virtualized',
'react-table',
'@hot-loader.*',
'webpack.*',
'@?babel.*',
'lodash.*',
'antd',
'@ant-design.*',
'.*bootstrap',
'moment',
'jquery',
'core-js.*',
'@emotion.*',
'd3.*',
].join('|')})/`,
),
},
// bundle large libraries separately
brace: {
name: 'brace',
test: /\/node_modules\/(brace|react-ace)\//,
priority: 40,
},
mathjs: {
name: 'mathjs',
test: /\/node_modules\/mathjs\//,
priority: 30,
enforce: true,
},
// viz thumbnails are used in `addSlice` and `explore` page
thumbnail: {
name: 'thumbnail',
test: /thumbnail(Large)?\.png/i,
priority: 20,
enforce: true,
},
},
},
@ -299,7 +349,7 @@ const config = {
},
],
},
/* for css linking images */
/* for css linking images (and viz plugin thumbnails) */
{
test: /\.png$/,
loader: 'url-loader',
@ -404,7 +454,7 @@ if (isDevMode) {
// Pass flag --analyzeBundle=true to enable
// e.g. npm run build -- --analyzeBundle=true
if (analyzeBundle) {
config.plugins.push(new BundleAnalyzerPlugin());
config.plugins.push(new BundleAnalyzerPlugin({ analyzerPort }));
}
// Speed measurement is disabled by default