Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有些js文件不想进行treeshaking,怎么配置 #997

Closed
HeWenKe opened this issue Sep 7, 2022 · 7 comments
Closed

有些js文件不想进行treeshaking,怎么配置 #997

HeWenKe opened this issue Sep 7, 2022 · 7 comments
Labels

Comments

@HeWenKe
Copy link

HeWenKe commented Sep 7, 2022

很多变量,定义后需要动态调用,但是打包的时候直接把变量打包没了

@rschristian
Copy link
Collaborator

Please provide a reproduction as well as the expected behavior.

@rschristian rschristian added the needs more info Needs more information label Sep 7, 2022
@HeWenKe
Copy link
Author

HeWenKe commented Sep 7, 2022

look under code
const a = 'a';
const b = 'b';
const c = 'c';
let ary = [];
for (let val of ['a','b','c']){
ary.push(eval(val))
}
console.log(ary)
//打包以上代码,会把变量a,b,c 全部remove 掉,导致我for 循环的时候,找不到


Edit by @rschristian for clarity:

const a = 'a';
const b = 'b';
const c = 'c';
let ary = [];
for (let val of ['a','b','c']){
  ary.push(eval(val))
}
console.log(ary)

a, b, and c are incorrectly stripped out, they're seen as dead code despite the later eval() call.

@rschristian
Copy link
Collaborator

This is probably an upstream issue, but will look into it.

@HeWenKe
Copy link
Author

HeWenKe commented Sep 7, 2022

perfect, can you speak chinese ? can ,netx time please speak it。wowo

@rschristian
Copy link
Collaborator

No, I cannot. Just tossed it into Google translate and hoped for the best.

@HeWenKe
Copy link
Author

HeWenKe commented Sep 7, 2022

ok,thanks

@rschristian rschristian added upstream and removed needs more info Needs more information labels Sep 9, 2022
@rschristian
Copy link
Collaborator

Upstream "issue" in Rollup, see: rollup/rollup#3228, rollup/rollup#2963

We don't really have a solution for this here, nor does there seem to be one upstream. Using eval is something that should be avoided whenever possible anyways.

Closing this out as there's nothing actionable for us here to my knowledge.

@rschristian rschristian closed this as not planned Won't fix, can't repro, duplicate, stale Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants