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
fix: respect "sideEffects: true" in package.json #5257
Conversation
There's a type error that needs to be fixed. |
I tried to find the issue, but the code looks right to me 🤔 |
We'd likely need |
But it is explicitly checked that it is |
Ah didn't notice that. Looks like you're right it is a bug, that's pretty strange. I'm not getting the warning in vscode though. |
Seems to be a |
@aleclarson #6019 was merged, could you make a rebase of this PR? 🙂 |
We can assume a package has side effects in this case. This is basically a way to force Rollup to always include the package when imported.
a76919c
to
2205182
Compare
Ready to merge ✅ |
still failing on types |
looks like Jest is using wrong tsconfig |
Do we already have a PR to fix it? Could you link it here? Then we can observe the progress of that fix. |
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no longer blockers now. I think we can merge this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
But maybe we should create a PR to plugin-node-resolve so that we don't misalign with rollup's behavior.
https://github.com/rollup/plugins/blob/bc5cf91a042b88e14a1da9ba25f501d92591ca8a/packages/node-resolve/src/util.js#L143-L164
@sapphi-red I thought that we were choosing a different trade-off here, avoiding the AST analysis in exchange for possible bigger bundles because we aren't letting rollup tree-shake modules in packages with side effects (as we assume that most of the module will be needed in that case anyways). I think for rollup, the best is to still try to do its best to create smaller bundlers. But thinking about the introduction of a misalignment with rollup, maybe this change isn't worth it. @aleclarson could you explain a bit more why you said:
There could be modules with side effects that export functions that could be tree-shaken, no? From https://rollupjs.org/plugin-development/#load
|
@bluwy maybe you could help us with the question above? |
Looking at it now, I'm not sure if this is correct too. rollup/rollup#3663 is when rollup supported |
@aleclarson please re-open the PR if we're missing something here. From the discussion above, I think we should close it for now. |
Description
We can assume a package has side effects in this case. This is basically a way to force Rollup to always include the package when imported.
Additional context
So when
moduleSideEffects
is set to true (what Vite currently uses), Rollup will statically analyze the AST to determine if tree-shaking can occur, but in reality, we never want tree-shaking to occur for modules declared inpkg.sideEffects
. To avoid tree-shaking (and potentially costly static analysis),moduleSideEffects
must be set tono-treeshake
.What is the purpose of this pull request?