Skip to content

Commit

Permalink
feat: webpack vendors chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
avlyalin committed Jun 6, 2020
1 parent 4ccb52d commit 1d3223f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ const {
colors: { transparent, current, black, white },
} = require('tailwindcss/defaultTheme');

const isDev = process.env.NODE_ENV === 'development';

module.exports = {
purge: ['./src/**/*.js', './assets/index.html'],
purge: { enabled: !isDev, content: ['./src/**/*.js', './assets/index.html'] },
theme: {
colors: {
transparent,
Expand Down
22 changes: 20 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const CopyPlugin = require('copy-webpack-plugin');

const isDev = process.env.NODE_ENV !== 'production';
const isDev = process.env.NODE_ENV === 'development';
const isAnalysis = process.env.NODE_ENV === 'analysis';

const plugins = [
Expand Down Expand Up @@ -36,6 +36,24 @@ module.exports = {
filename: 'app.[hash].js',
},
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 5000,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
const packageName = module.context.match(
/[\\/]node_modules[\\/](.*?)([\\/]|$)/,
)[1];

return `vendors.${packageName.replace('@', '')}`;
},
},
},
},
minimizer: [new TerserJSPlugin(), new OptimizeCSSAssetsPlugin()],
},
module: {
Expand Down Expand Up @@ -71,7 +89,7 @@ module.exports = {
},
resolve: {
alias: {
'react-dom': '@hot-loader/react-dom',
'react-dom': isDev ? '@hot-loader/react-dom' : 'react-dom',
assets: path.resolve(__dirname, './assets'),
src: path.resolve(__dirname, './src'),
_storybook: path.resolve(__dirname, './.storybook'),
Expand Down

0 comments on commit 1d3223f

Please sign in to comment.