昨天给项目配置vue多页面,结果一跑起来就报错:
RangeError: Maximum call stack size exceeded- Array.join- loader.js:228 Function.Module._findPathinternal/modules/cjs/loader.js:228:56- loader.js:591 Function.Module._resolveFilenameinternal/modules/cjs/loader.js:591:25- loader.js:520 Function.Module._loadinternal/modules/cjs/loader.js:520:25- loader.js:650 Module.requireinternal/modules/cjs/loader.js:650:17- helpers.js:20 requireinternal/modules/cjs/helpers.js:20:18- extract-chunks.js:35 getNames[vue-cli3-import-test]/[@vue]/preload-webpack-plugin/src/lib/extract-chunks.js:35:22- extract-chunks.js:44 getNames[vue-cli3-import-test]/[@vue]/preload-webpack-plugin/src/lib/extract-chunks.js:44:21
这是因为 @vue/preload-webpack-plugin 这个插件在打包过程中创建chunks 有问题,导致循环依赖。
解决方案:将每个单页的中 预载插件移除。
// vue.config.jsconst pagesObject = {index:{// page 的入口entry:'src/main.js', // 模板来源template:'public/index.html',// 在 dist/index.html 的输出filename:'index.html',// 当使用 title 选项时,// template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>// title:'index',// 提取出来的通用 chunk 和 vendor chunk。// chunks: ["chunk-vendors", "chunk-common", "index"]},promotion:{entry:'src/pages/promotion/promotion.js',template:'public/promotion.html',filename:'promotion.html',// title:'promotion',// chunks: ["chunk-vendors", "chunk-common", "promotion"]}};module.exports = {pages:pagesObject,chainWebpack: config => {// TODO: Remove this workaround once https://github.com/vuejs/vue-cli/issues/2463 is fixed// Remove preload plugins for multi-page build to prevent infinite recursionObject.keys(pagesObject).forEach(page => {config.plugins.delete(`preload-${page}`)config.plugins.delete(`prefetch-${page}`)})},
}
参考链接