pref: JS bundling improvements (#1461)

* perf: Split only initial vendors
This commit is contained in:
Tom Moor
2020-08-17 22:09:12 -07:00
committed by GitHub
parent d885252fb0
commit 0555fd2caa
2 changed files with 34 additions and 20 deletions

View File

@ -10,30 +10,30 @@ require('dotenv').config({ silent: true });
module.exports = { module.exports = {
output: { output: {
path: path.join(__dirname, 'dist'), path: path.join(__dirname, 'dist'),
filename: 'bundle.js', filename: '[name].[hash].js',
publicPath: '/static/', publicPath: '/static/',
}, },
module: { module: {
rules: [ rules: [
{ {
test: /\.js$/, test: /\.js$/,
loader: 'babel-loader', loader: 'babel-loader',
exclude: [ exclude: [
path.join(__dirname, 'node_modules') path.join(__dirname, 'node_modules')
], ],
include: [ include: [
path.join(__dirname, 'app'), path.join(__dirname, 'app'),
path.join(__dirname, 'shared'), path.join(__dirname, 'shared'),
], ],
options: { options: {
cacheDirectory: true cacheDirectory: true
} }
}, },
// inline base64 URLs for <=8k images, direct URLs for the rest // inline base64 URLs for <=8k images, direct URLs for the rest
{ test: /\.(png|jpg|svg)$/, loader: 'url-loader' }, { test: /\.(png|jpg|svg)$/, loader: 'url-loader' },
{ {
test: /\.woff$/, test: /\.woff$/,
loader: 'url-loader?limit=1&mimetype=application/font-woff&name=public/fonts/[name].[ext]', loader: 'url-loader?limit=1&mimetype=application/font-woff&name=public/fonts/[name].[ext]',
}, },
{ test: /\.md/, loader: 'raw-loader' }, { test: /\.md/, loader: 'raw-loader' },
] ]
@ -64,4 +64,17 @@ module.exports = {
stats: { stats: {
assets: false, assets: false,
}, },
optimization: {
runtimeChunk: 'single',
moduleIds: 'hashed',
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'initial',
},
},
},
}
}; };

View File

@ -7,17 +7,18 @@ const TerserPlugin = require('terser-webpack-plugin');
commonWebpackConfig = require('./webpack.config'); commonWebpackConfig = require('./webpack.config');
productionWebpackConfig = Object.assign(commonWebpackConfig, { productionWebpackConfig = Object.assign(commonWebpackConfig, {
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].[contenthash].js',
publicPath: '/static/',
},
cache: true, cache: true,
mode: "production", mode: "production",
devtool: 'source-map', devtool: 'source-map',
entry: ['./app/index'], entry: ['./app/index'],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.[hash].js',
publicPath: '/static/',
},
stats: "normal", stats: "normal",
optimization: { optimization: {
...commonWebpackConfig.optimization,
minimizer: [ minimizer: [
new TerserPlugin({ new TerserPlugin({
terserOptions: { terserOptions: {