does typescript with webpack tree shaking work with es5?

Viewed 289

i have a module which is javascript ES5 module called phaser. It also contains type declarations.

In my main.ts file, i have

import * as phaser from 'phaser'

If i build it using webpack, (I am using ts-loader for module rules in webpack), What happens is the final output doesn't contain phaser at all. If i add console.log(phaser) to my file, then the build output contains phaser library.

Question: Seems like because of I don't use phaser , tree shaking works, but why? I am asking because, phaser is written in ES5,so even though i am importing it as ES6, tree shaking still shouldn't work. A good example of this is that if I change main.ts to main.js and have only importing statement as i have above, even though I don't console.log(phaser), the final build will contain phaser . Looks like it's something related to ts-loader or tsconfig.json? Any ideas? I have empty tsconfig.json not to complicate things.

0 Answers
Related