Skip to content

Commit 1d3223f

Browse files
committed
feat: webpack vendors chunks
1 parent 4ccb52d commit 1d3223f

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

tailwind.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ const {
22
colors: { transparent, current, black, white },
33
} = require('tailwindcss/defaultTheme');
44

5+
const isDev = process.env.NODE_ENV === 'development';
6+
57
module.exports = {
6-
purge: ['./src/**/*.js', './assets/index.html'],
8+
purge: { enabled: !isDev, content: ['./src/**/*.js', './assets/index.html'] },
79
theme: {
810
colors: {
911
transparent,

webpack.config.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
77
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
88
const CopyPlugin = require('copy-webpack-plugin');
99

10-
const isDev = process.env.NODE_ENV !== 'production';
10+
const isDev = process.env.NODE_ENV === 'development';
1111
const isAnalysis = process.env.NODE_ENV === 'analysis';
1212

1313
const plugins = [
@@ -36,6 +36,24 @@ module.exports = {
3636
filename: 'app.[hash].js',
3737
},
3838
optimization: {
39+
runtimeChunk: 'single',
40+
splitChunks: {
41+
chunks: 'all',
42+
maxInitialRequests: Infinity,
43+
minSize: 5000,
44+
cacheGroups: {
45+
vendor: {
46+
test: /[\\/]node_modules[\\/]/,
47+
name(module) {
48+
const packageName = module.context.match(
49+
/[\\/]node_modules[\\/](.*?)([\\/]|$)/,
50+
)[1];
51+
52+
return `vendors.${packageName.replace('@', '')}`;
53+
},
54+
},
55+
},
56+
},
3957
minimizer: [new TerserJSPlugin(), new OptimizeCSSAssetsPlugin()],
4058
},
4159
module: {
@@ -71,7 +89,7 @@ module.exports = {
7189
},
7290
resolve: {
7391
alias: {
74-
'react-dom': '@hot-loader/react-dom',
92+
'react-dom': isDev ? '@hot-loader/react-dom' : 'react-dom',
7593
assets: path.resolve(__dirname, './assets'),
7694
src: path.resolve(__dirname, './src'),
7795
_storybook: path.resolve(__dirname, './.storybook'),

0 commit comments

Comments
 (0)