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

unnamed import is being shaken away with tree shaking #1078

Closed
PieterSwitten opened this issue Oct 2, 2018 · 5 comments
Closed

unnamed import is being shaken away with tree shaking #1078

PieterSwitten opened this issue Oct 2, 2018 · 5 comments

Comments

@PieterSwitten
Copy link

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 matthewp added the bug label Oct 2, 2018
@matthewp
Copy link
Member

matthewp commented Oct 2, 2018

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

@matthewp matthewp added the p1 label Oct 2, 2018
@matthewp matthewp self-assigned this Oct 2, 2018
@frank-dspeed
Copy link
Contributor

frank-dspeed commented Oct 4, 2018

@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
Copy link
Member

matthewp commented Oct 4, 2018

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
Copy link
Member

matthewp commented Oct 4, 2018

#1081

@matthewp
Copy link
Member

matthewp commented Oct 4, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants