typescript-webpack-tree-shaking icon indicating copy to clipboard operation
typescript-webpack-tree-shaking copied to clipboard

Question regarding ES5/ES2015

Open amitdahan opened this issue 8 years ago • 4 comments

Hey first of all, thanks for putting order into the chaos which is the current state of typescript-treeshaking!

I only have one question. So the reason the Babili build is only transpiling to ES2015 is because the plugin itself needs ES2015 code to properly analyze dead code? So in this case if need an ES5 bundle, we'd need to manually (or separately) transpile the bundle into ES5, or is there a way to tell Babili to eventually spit out ES5 code instead of ES2015?

Thanks!!

amitdahan avatar Dec 27 '16 08:12 amitdahan

First yes, Babili needs ES2015 code to operate properly, It accepts ES5 also, but won't remove the unused classes. Babili is basically a set of Babel presets, so if it is possible to inject more presets to the plugin it will work to output ES5 code in the end. If it doesn't work from code, try adding them to .babelrc

sonicoder86 avatar Dec 27 '16 11:12 sonicoder86

For ES5 bundle, it seems not working to use tree shaking with Babili.

beiciye avatar Jan 19 '17 06:01 beiciye

Maybe not the right place to ask this question, but @blacksonic do you know why webpack doesn't directly remove the detected unused exports? But instead hands it over to Uglify to do the job, which it can't easily do because the static semantic is already lost after es6->es5 transpilation?

jack4it avatar Jan 31 '17 22:01 jack4it

@jack4it I think it is designed this way. Maybe after the release of Webpack 2 they will implement Rollup like tree-shaking

sonicoder86 avatar Feb 25 '17 19:02 sonicoder86