-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add sideEffects
property to package.json for our packages
#13910
Comments
@talldan should we enable |
@talldan do you plan to continue work on this issue? We added this flag to many packages where it was straightforward. I would be fine with closing this issue if handling the rest is too complicated and thus unreliable in the long run. |
@gziolo Sorry for missing your pings. I didn't realise I'd self-assigned this. I stopped working on the eslint rule for package side effects (#14135)—although it half-worked there were too types of side-effects it didn't catch. I should've unassigned myself when closing that. I think you're right, having an open issue here doesn't add much value. I think it's fine to continue on a case by case basis for packages and close this. Thanks for handling those PRs 👍 . |
Description
The
sideEffects
property indicates whether a package introduces any side effects. It can be specified as eitherfalse
or as an array of files that have side effects.By specifying this property, webpack is able to reduce the size of JavaScript bundles by eliminating unused imports:
https://webpack.js.org/guides/tree-shaking/
sideEffects
is particularly relevant when implementing feature flags. Without it, features need to be flagged at every possible point. For further details, see this discussion: #13829 (comment)How to implement this
Packages will need to be assessed individually. The biggest cause of side effects is likely to be
registerStore
. Any function call in the outer-most scope can result in a side-effect, particularly if there's no return value:Mutation of global or imported variables is another example:
Another good indication is any import that doesn't define any new variables. The imported file will almost certainly have side-effects:
Other ideas
It might be possible to use a linting rule to enforce this. A quick look at npm shows limited prior art, so a custom rule might be needed.
The text was updated successfully, but these errors were encountered: