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

feat(node-resolve): add ignoreSideEffectsForRoot option #694

Merged
merged 6 commits into from
Feb 14, 2021

Conversation

tjenkinson
Copy link
Member

@tjenkinson tjenkinson commented Dec 7, 2020

Rollup Plugin Name: resolve

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes
  • no

Breaking Changes?

  • yes
  • no

List any relevant issue numbers: #692

Description

Use the rootDir option to determine if the file being resolved is in the root package, and if it is do not respect the package.json side-effects option, providing ignoreSideEffectsForRoot is true.

Note the default is remaining as false and we are not treating this as a bug, because false matches the default behaviour in webpack.

Refs #692

@tjenkinson tjenkinson marked this pull request as ready for review December 7, 2020 17:46
@LarsDenBakker
Copy link
Contributor

I'm not sure if this is a bug, why should side effects setting not apply to the project itself?

@tjenkinson
Copy link
Member Author

Yeh I was wondering this. I think if the package.json option is false you might only expect it to apply to the entry point for users. I’ll have a look and see what webpack does.

@07akioni
Copy link

07akioni commented Dec 8, 2020

I'm not sure if this is a bug, why should side effects setting not apply to the project itself?

I'm not sure about the behavior too. However I think it should be as least documented, or maybe made as an option?

For example I'm making a non-side-effects library, and the doc site is placed in the project root too. If I use rollup to create a doc site bundle (which vite does), css (for the site) may be shaken by rollup. When I apply sideEffects: false in package.json, I only want the entry point to be shaken.

Currently I need to remove sideEffects field in package.json before I build the doc site and add it after the site is built. Another workaround is to add docs dir in sideEffects.

What makes things confused is that

with plugin-node-resolve side-effects: false side-effects-shaken (code outside node_modules)

If you only use node resolve for extension resolving (not using any module from node_modules), you will find bundle result differs with or without plugin-node-resolve when sideEffects is marked as false.

@LarsDenBakker
@tjenkinson

@tjenkinson
Copy link
Member Author

Finally got around to trying this with webpack.

If you

cd packages/node-resolve/test/fixtures/root-package-side-effect
npm i --save-dev webpack@5.11.0 webpack-cli@4.2.0
npx webpack --entry "./index.js"

the output build is empty, so it looks like webpack works the same way the plugin does currently.

So maybe we should keep the plugin consistent with webpack? I agree it could be a bit confusing though if you're not using node-resolve, and then when you add it to an existing project it initially does not behave like a no-op.

@shellscape
Copy link
Collaborator

It might be worth comparing to webpack@4, since v5 is still a bit of a trash can fire.

@tjenkinson
Copy link
Member Author

With webpack 4.44.2 it also does not include 'side-effect.js' with "sideEffects": false

@shellscape
Copy link
Collaborator

I think webpack has set good precedent here and following their lead is reasonable. I also think documenting this as suggested by @07akioni is a great idea. @LarsDenBakker and @07akioni could you take another look at this one please?

LarsDenBakker
LarsDenBakker previously approved these changes Jan 20, 2021
@tjenkinson
Copy link
Member Author

So if we are following webpack we should close this PR and update the docs. @LarsDenBakker just saw you approved. Do you think we should do different to weback?

@LarsDenBakker
Copy link
Contributor

Sorry I misunderstood, I thought webpack does what youre proposing in this PR. Lets keep it as is then.

@shellscape
Copy link
Collaborator

😆 I'll wait from direction from you both on when/if to merge.

@tjenkinson
Copy link
Member Author

I think given webpack introduced this(?) we should match their behaviour by default.

We could update this pr to add an ignoreSideEffectsForRoot option though?

If we think it's worth it I can add that otherwise fine closing this.

@shellscape
Copy link
Collaborator

I'm good adding that option.

@tjenkinson tjenkinson changed the title fix(node-resolve): ignore package sideEffects property for root package feat(node-resolve): add ignoreSideEffectsForRoot option Jan 31, 2021
@tjenkinson
Copy link
Member Author

I'm good adding that option.

@shellscape done! @07akioni ignoreSideEffectsForRoot should work for your use case :)

@07akioni
Copy link

Hope this can be merged soon. 😄

@shellscape shellscape merged commit 7359d1f into master Feb 14, 2021
@shellscape shellscape deleted the root-package-side-effect branch February 14, 2021 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants