From d80f4062394a25c6d10aac22b82ffe4463f3d338 Mon Sep 17 00:00:00 2001 From: Jesse Yang Date: Thu, 10 Sep 2020 15:11:21 -0700 Subject: [PATCH] build: optimize webpack code split (#10831) --- superset-frontend/webpack.config.js | 62 ++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/superset-frontend/webpack.config.js b/superset-frontend/webpack.config.js index 97d3536e17..500a129b49 100644 --- a/superset-frontend/webpack.config.js +++ b/superset-frontend/webpack.config.js @@ -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