Skip to content

Commit

Permalink
Disable initial chunks split
Browse files Browse the repository at this point in the history
  • Loading branch information
theninthsky committed Nov 8, 2022
1 parent 52f3fd4 commit 5d23748
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions public/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = (mainScripts, pages) => `
module.exports = (initialScripts, pages) => `
<!DOCTYPE html>
<html lang="en">
<head>
Expand Down Expand Up @@ -69,7 +69,7 @@ module.exports = (mainScripts, pages) => `
}
</script>
${mainScripts.map(({ name, source }) => `<script id="${name}" type="module">${source}</script>`).join('\n')}
${initialScripts.map(({ name, source }) => `<script id="${name}" type="module">${source}</script>`).join('\n')}
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
5 changes: 5 additions & 0 deletions public/serve.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rewrites": [
{ "source": "/*", "destination": "/index.html" }
]
}
7 changes: 3 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ module.exports = (_, { mode }) => {
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'initial',
chunks: 'async',
minSize: 40000,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
chunks: 'all',
name: (module, chunks) => {
const allChunksNames = chunks.map(({ name }) => name).join('.')
const moduleName = (module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/) || [])[1]
Expand All @@ -94,7 +93,7 @@ module.exports = (_, { mode }) => {
inject: false,
templateContent: ({ htmlWebpackPlugin, compilation }) => {
const assets = compilation.getAssets()
const mainScripts = htmlWebpackPlugin.files.js
const initialScripts = htmlWebpackPlugin.files.js
.map(script => assets.find(({ name }) => decodeURIComponent(script).slice(1) === name))
.map(({ name, source }) => ({ name, source: source._children[0]._value }))

Expand All @@ -108,7 +107,7 @@ module.exports = (_, { mode }) => {
return { path, scripts, data }
})

return htmlTemplate(mainScripts, pages)
return htmlTemplate(initialScripts, pages)
}
}),
new CopyPlugin({
Expand Down

0 comments on commit 5d23748

Please sign in to comment.