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 是按模块来的,在这个文件这么导出,会被认为是一个模块

0
0

从基础到实战 手把手带你掌握新版Webpack4.0

知识点+项目实例+原理讲解 全方位解析Webpack4新版本

3615 学习 · 1291 问题

查看课程