Skip to content

Instantly share code, notes, and snippets.

@philippegirard
Created August 3, 2021 21:21
Show Gist options
  • Save philippegirard/01fd4e68795a89194035c2c21a9177b6 to your computer and use it in GitHub Desktop.
Save philippegirard/01fd4e68795a89194035c2c21a9177b6 to your computer and use it in GitHub Desktop.
webpack5
const { environment } = require('@rails/webpacker')
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
environment.plugins.prepend("CleanWebpackPlugin", new CleanWebpackPlugin());
// default config from https://webpack.js.org/plugins/split-chunks-plugin/#optimizationsplitchunks
environment.splitChunks((config) =>
Object.assign({}, config, {
optimization: {
splitChunks: {
chunks: "all", // changed to "all" from "async" in default
minSize: 20000,
// minRemainingSize: 0, // this option does not work with webpack even included in default
maxSize: 0,
minChunks: 1,
maxAsyncRequests: 30,
maxInitialRequests: 30,
automaticNameDelimiter: "~",
enforceSizeThreshold: 50000,
cacheGroups: {
defaultVendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10,
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
},
},
})
);
module.exports = environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment