stealjs / steal-tools

Build easy. Load fast.
https://stealjs.com/docs/steal-tools.html
MIT License
67 stars 23 forks source link

unnamed import is being shaken away with tree shaking #1078

Closed PieterSwitten closed 5 years ago

PieterSwitten commented 5 years ago

According to 'https://stealjs.com/docs/steal-tools.tree-shaking.html#preventing-code-removal' the imports without a variable should not be removed in the build by tree shaking.

When I do a import like import './foobar.js' It will removed after the build. Inside foobar.js there is only one line with console.log('foobar');.

I have to explicit export something before it is not being removed in the build.

console.log('foobar');
export default {};

Then it does work after I have build.

Is this a bug in the tree shaking or is it the expected result and should we update our code?

matthewp commented 5 years ago

It's a bug, I thought I had a test for this though. Will check it out.

frank-dspeed commented 5 years ago

@matthewp my old suggestion was wrong i now see the fail the fail is we import some thing that exports nothing look exactly at his code its not a global that gets treeshaken away he did not export anything so there is nothing

@PieterSwitten this is expected result!

Dont works

When I do a import like import './foobar.js' It will removed after the build. Inside foobar.js there is only one line with console.log('foobar');.

main.js

import './foobar.js' 

foobar.js

console.log('foobar');.

Works

I have to explicit export something before it is not being removed in the build.

foobar.js

console.log('foobar');
export default {};

Then it does work after I have build.

this is because the depdency foobar in the don't works example simply exports nothing this is not what we talk about in 'https://stealjs.com/docs/steal-tools.tree-shaking.html#preventing-code-removal'

matthewp commented 5 years ago

Ok, so there is a similar test, however the test exports a function. Once I removed the export the test no longer works. So I was able to recreate this. Now to figure out why...

matthewp commented 5 years ago

https://github.com/stealjs/steal-tools/pull/1081

matthewp commented 5 years ago

Fixed in https://github.com/stealjs/steal-tools/releases/tag/v2.0.6