捆绑的转口在图书馆树中是否摇动了?

时间:2019-09-12 04:41:57

标签: javascript webpack

说我有一个包含以下index.js文件的库

import { a } from './a'
import { b } from './b'
import { c } from './c'
import { d } from './d'

export const myLibrary = {
    a, b, c, d
}

export default myLibrary

如果使用Webpack的使用者使用该库并使用以下语法:

import myLibrary from 'my-library'

myLibrary.a('Only include this function')

是否会通过摇树将b()c()d()从最终捆绑中移除?

1 个答案:

答案 0 :(得分:0)

export const myLibrary = {
    a, b, c, d
}

export default myLibrary

目前这不是可摇树的,但是webpack 5.x中应支持摇树这种语法。

import {a} from './a'
import {b} from './b'
import {c} from './c'

export { a, b, c }

以上语法在4.x中对树摇动的支持有限,在5.x中将完全被树摇动。该语法当前在webpack@next

中可被树摇晃