gpt4 book ai didi

javascript - 如果webpack摇树处理node_modules?

转载 作者:行者123 更新时间:2023-12-03 03:24:34 25 4
gpt4 key购买 nike

我正在处理node@6.11.0、webpack@3.4.1

文件.js

export function foo () {
return 'foo'
}

export function bar() {
return 'bar'
}

main.js

import { foo } from './file'
import { log } from 'mathjs'
foo()
log(10000,10)

bundle.js 包含 math.js 中的所有方法,所以我想知道 tree-shaking 是否有效。并且功能栏已使用 /* 未使用的和声导出栏 */ 进行签名当我使用 tree-shaking 时,bundlejs 应该只包含 foo 和 lod 方法,不是吗?git克隆https://github.com/z2014/All-test-demo,并测试

最佳答案

未使用的代码会被压缩器(例如 UglifyJS)删除。 Tree-shaking 只是让压缩器可以将其删除。

因此,就您而言,启用 UglifyJS 很可能会解决问题。

您可以阅读有关此行为的更多信息 https://webpack.js.org/guides/tree-shaking , https://github.com/webpack/webpack/tree/master/examples/harmony-unusedhttps://github.com/webpack/webpack/issues/2866

关于javascript - 如果webpack摇树处理node_modules?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46388918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com