tree-sharing 不生效的问题
来源:7-4 Vue CLI 3 的配置方法及课程总结(2)
诺巴蒂
2021-12-15
场景1
test.js
export const test1 = () => { console.log(1); };
export const test2 = () => { console.log(2); };
index.js
import { test1 } from './test';
console.log(test1);
test2 不会被 sharking
场景2
test.js
import test1 from './test1';
import test2 from './test2';
export {
test1,
test2,
};
index.js
import { test1 } from './test';
console.log(test1);
test2 会被sharking
场景3
test.js
export { default as test1 } from './test1';
export { default as test2 } from './test2';
index.js
import { test1 } from './test';
console.log(test1);
test2 会被sharking
老师为啥场景1 test2 不能被sharking,再经过一层引入就可以了
写回答
1回答
-
Dell
2021-12-18
tree shaking 是按模块来的,在这个文件这么导出,会被认为是一个模块
00
相似问题