-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v2 includes runtimeChunk twice with optimization.runtimeChunk option in webpack v4 #61
Comments
optimization.runtimeChunk
in webpack v4optimization.runtimeChunk
option in webpack v4
optimization.runtimeChunk
option in webpack v4
I can verify this error. My optimization config is: optimization: {
runtimeChunk: {
name: 'bootstrap'
},
splitChunks: {
chunks: 'initial',
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor'
}
}
},
} And both bootstrap and vendor show up twice from the return of flushChunks. |
I have the same issue and use the same setup. This is caused because the To still be able to work with webpack 4 i'm using my own script to extract the list of files (until a fix will be up) import { flatten, includes } from 'lodash';
function filesFromChunks(chunkNames, assets, checkChunkNames) {
const hasChunk = entry => {
const result = !!assets[entry];
if (!result && checkChunkNames) {
console.warn(`Unable to find ${entry} in Webpack chunks.`);
}
return result;
};
const entryToFiles = entry => assets[entry];
return [].concat(...chunkNames.filter(hasChunk).map(entryToFiles));
}
export default function chunksMap(clientStats) {
const publicPath = clientStats.publicPath.replace(/\/$/, '');
const beforeAssets = filesFromChunks(['bootstrap', 'vendor'], clientStats.assetsByChunkName);
const afterAssets = filesFromChunks(['main'], clientStats.assetsByChunkName);
return function flushChunks(chunkNames) {
const mainAssets = flatten(chunkNames.map(chunkName => clientStats.namedChunkGroups[chunkName].assets));
const allNeededAssets = [...beforeAssets, ...mainAssets, ...afterAssets];
const jsAssets = allNeededAssets
.filter(asset => includes(asset, '.js'))
.map(file => `<script type='${includes(file, '.map') ? 'application/json' : 'text/javascript'}' src='${publicPath}/${file}' defer></script>`)
.join('\n');
return {
js: jsAssets,
};
};
} That's only for JS files. |
Thanks for finding this! I’ll patch the duplicate |
When using one of the older webpack config setups. Bootstrap is duplicated and executed twice #61
@slavab89 @akash5474 Ill push a next tag on npm as well |
on npm, let me know if thats better |
@ScriptedAlchemy I just tried out next and it definitely works for me. |
Fantastic. Apologies for the error! Thank you @akash5474 for reporting it! Gonna merge this baby |
@ScriptedAlchemy Np and thanks for getting this fixed, working great now. Appreciate all the work you're doing with these libs. |
I noticed that my JS was running twice after upgrading to
webpack-flush-chunks@2.0.0
when usingoptimization.runtimeChunk
option in webpack v4.My
runtimeChunk
bootstrap.js
gets included twice in the htmlI've confirmed that this no longer happens if I remove
optimization.runtimeChunk
from the webpack config or switch back towebpack-flush-chunks@1.2.3
.Example Repo
https://github.com/akash5474/universal-demo/tree/bug-demo
Changes Made
Forked faceyspacey/universal-demo and made the following changes (akash5474/universal-demo@764c1be and akash5474/universal-demo@fd65e57):
Added a
console.log("hello world")
statement tosrc/index.js
to demonstrate the issue.Updated to the following dependency versions:
Updated webpack configs to work with new dependency versions
Deleted some unnecessary code
Steps to reproduce
Open http://localhost:3000 in the browser and open the console.
You will see "hello world" is logged twice.
Viewing the source html you will see bootstrap.js is included twice
This can be resolved by removing the following from webpack client config:
However after downgrading to
webpack-flush-chunks@1.2.3
,bootstrap.js
is only included once with theoptimization.runtimeChunk
option included. This suggests that the problem was introduced inwebpack-flush-chunks@2.0.0
Let me know if you have any questions or if I can help in any way. Thanks.
The text was updated successfully, but these errors were encountered: