mweststrate / import-size

Measure the real, minified, tree-shaken impact of individual imports into your app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Include 0-import cost

Andarist opened this issue · comments

It would be great if it could also always report 0-import cost. What I mean is basically always also trying entry with this:

return `import "${library}";`;

It would serve as a good basic test for treeshakeability as a whole. To get reliable tests for this we'd have to remove sideEffects: false from the imported module - or force webpack to ignore it. Otherwise, it most likely would always report 0, even for non-treeshakeable modules.

I tried that, but it is basically interpreted as a side-effect full import, always yielding the same result as * as from what I tried, so didn't seen to add any value.

I've done preliminary investigation and it seems that's the fault of used import-size package. It "transforms" import "${library}"; input to import * as tmp from "${library}";console.log(tmp);. Making it effectively the same as import * as "${library}"; input.

This happens here:
https://github.com/wix/import-cost/blob/a8b24cce7ef4bc7836d28a2913d3788eabc56cda/packages/import-cost/src/babelParser.js#L112

So to make what I've requested to work we should reach out to them to see if they would like to support calculating costs for bare imports, probably behind a flag or something.