-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
使用multi-page模式时chunks无法注入script #4944
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
Comments
很抱歉,请问能否更详细地描述一下你碰到的问题,以及需要我们实现什么功能? 另外,对于 Bug 反馈,我们是要求必须提供可以运行的复现代码的(最好是一个 Git 仓库) |
@sodatea 内容已更新,请看一下。谢谢 |
chunks: ['vendors', 'chunk-vendors', 'chunk-common', name], |
|
可以不设置,如果这里没有设置,那么会有一个默认值会处理这个参数 |
这一个的问题是 html-webpack-plugin 这个插件处理问题 |
这里我也没懂你要 CLI 实现什么…… |
@sodatea 是所有的chunks都没有注入到页面。 /**
* Return all chunks from the compilation result which match the exclude and include filters
* @param {any} chunks
* @param {string[]|'all'} includedChunks
* @param {string[]} excludedChunks
*/
filterChunks (chunks, includedChunks, excludedChunks) {
return chunks.filter(chunkName => {
// Skip if the chunks should be filtered and the given chunk was not added explicity
if (Array.isArray(includedChunks) && includedChunks.indexOf(chunkName) === -1) {
return false;
}
// Skip if the chunks should be filtered and the given chunk was excluded explicity
if (Array.isArray(excludedChunks) && excludedChunks.indexOf(chunkName) !== -1) {
return false;
}
// Add otherwise
return true;
});
} 修改后的代码: /**
* Return all chunks from the compilation result which match the exclude and include filters
* @param {any} chunks
* @param {string[]|{test(chunkName: string): boolean}|((chunkName: string) => boolean)|'all'} includedChunks
* @param {string[]|{test(chunkName: string): boolean}|((chunkName: string) => boolean)} excludedChunks
*/
filterChunks (chunks, includedChunks, excludedChunks) {
return chunks.filter(chunkName => {
// Skip if the chunks should be filtered and the given chunk was not added explicity
if (Array.isArray(includedChunks) && includedChunks.indexOf(chunkName) === -1) { // chunks: Array
return false;
} else if (includedChunks instanceof RegExp) { // chunks: RegExp
return includedChunks.test(chunkName);
} else if (typeof includedChunks === 'function') { // chunks: Function
return includedChunks(chunkName);
}
// if (Array.isArray(includedChunks) && includedChunks.indexOf(chunkName) === -1) {
// return false;
// }
// Skip if the chunks should be filtered and the given chunk was excluded explicity
if (Array.isArray(excludedChunks) && excludedChunks.indexOf(chunkName) !== -1) { // chunks: Array
return false;
} else if (excludedChunks instanceof RegExp) { // chunks: RegExp
return !excludedChunks.test(chunkName);
} else if (typeof excludedChunks === 'function') { // chunks: Function
return excludedChunks(chunkName);
}
// if (Array.isArray(excludedChunks) && excludedChunks.indexOf(chunkName) !== -1) {
// return false;
// }
// Add otherwise
return true;
});
} |
我大概懂你的问题了(虽然还是没明白什么情况下才会出现这个问题) 但既然是上游插件的问题的话,我认为 Vue CLI 不应该为了修一个小 bug 而直接 fork 过来改。我们没有这个精力保证后续的持续维护。 如果你实在有需要,可以自己在 package.json 里添加 resolutions 字段,把 html-webpack-plugin 指向你 fork 修改后的 GitHub 仓库 (yarn 直接支持解析 resolutions,npm 可以用 https://www.npmjs.com/package/npm-force-resolutions) |
Version
3.11.0
Environment info
Steps to reproduce
What is expected?
能够正常渲染出页面
What is actually happening?
在使用vue-cli创建一个工程时,使用multi-page模式。配置 pages 参数。
通执 serve 和 build 后,页面相关的 chunks 不会被注入到 HTML文件中,导致页面无法执行渲染。
在排查过程中,发现 html-webpack-plugin 插件在处理 chunks 参数时采用的是 绝对匹配 的方式来过滤 chunk。 我在 html-webpack-plugin ##的github也提了issue( #jantimon/html-webpack-plugin#1319 ),如果 html-webpack-plugin的作者不采纳,cli 这边能否实现呢?
The text was updated successfully, but these errors were encountered: