Skip to content

Instantly share code, notes, and snippets.

@mpg-tomoya-komiyama
Created May 27, 2021 07:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpg-tomoya-komiyama/f2a06cba2dfe4f6a9ecd1395ca2ea97c to your computer and use it in GitHub Desktop.
Save mpg-tomoya-komiyama/f2a06cba2dfe4f6a9ecd1395ca2ea97c to your computer and use it in GitHub Desktop.
webpack config for grouping multi entries
const common = (env) => ({ /* 共通設定 */ })
const packsPath = path.join(__dirname, "app", "javascript", "packs")
const entryTypes = {
root: "*.ts",
customer: "customers/**/*.ts",
admin: "admin/**/*.ts",
}
module.exports = Object.keys(entryTypes).map((key) => (env) => ({
...common(env),
entry: glob.sync(`${packsPath}/${entryTypes[key]}`).reduce((p, filePath) => {
p[path.relative(packsPath, filePath).replace(".ts", "")] = path.resolve(__dirname, filePath)
return p
}, {}),
optimization: {
splitChunks: {
name: `vendor-${key}`,
chunks: "initial",
minChunks: 3,
},
},
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment