fix: 修复第三方包的 chunk 被随机到组件的问题

This commit is contained in:
sight 2022-04-23 19:54:50 +08:00
parent 11b8f18033
commit 09ea8472ab

View File

@ -60,9 +60,15 @@ export default (): UserConfigExport => {
vue: "Vue", vue: "Vue",
}, },
manualChunks(id) { manualChunks(id) {
console.log("mmmmm",id);
let arr = id.toString().split('/'); let arr = id.toString().split('/');
if (arr.length >= 2) { if (id.includes('node_modules')) {
//if (arr.length >= 2 && arr[arr.length - 1].split('.')[1] != 'ts'){ //id => layui-vue/node_modules/.pnpm/@vue+devtools-api@6.1.4/node_modules/@vue/devtools-api/lib/esm/api/app.js
const chunksName = "_chunks/";
return chunksName + id.toString().split('node_modules/')[2].split('/')[0].toString();
} else if (arr.length >= 2){
//if (arr.length >= 2 && arr[arr.length - 1].split('.')[1] != 'ts'){
let entryPoint = arr[arr.length - 2].toString() let entryPoint = arr[arr.length - 2].toString()
if (matchModule.includes(entryPoint)) { if (matchModule.includes(entryPoint)) {
return entryPoint; return entryPoint;