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

chore: add sideEffects false to package.json #5025

Merged
merged 4 commits into from Oct 30, 2022
Merged

Conversation

me4502
Copy link
Contributor

@me4502 me4502 commented Oct 6, 2022

This flag within the package.json file allows marking that a package does not make use of side effects, as documented here: https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free

Side effects in this context are basically just any action that happens purely from importing a file, without calling or using anything that the file exports. I had a look through the axios codebase, and couldn't find any instances of actual side effects. There were a few prototype usages, but those all seemed to be modifying something within the same file, so therefore aren't side effects.

The point of this change is that it tells bundlers/optimisers that they're able to minimise to remove entire unused files from axios when a consuming app uses a part of axios but not all of it. While most bundlers/optimisers try to do this, side effect detection is very finicky and often incorrectly finds side effects. Providing this hint removes the chance of false positives, allowing better bundling optimisations for consuming applications.

This will have no effect on the actual axios build itself, only on how bundlers in consuming applications treat it when imported.

I didn't make an issue sorry as this is a single line change, so creating this pull request is no more time consuming and allows showing what the proposed change is.

me4502 and others added 4 commits October 6, 2022 11:50
This flag within the package.json file allows marking that a package does not make use of side effects, as documented here: https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free
There was no EOL in the original, so removing it to minimise diff
@jasonsaayman jasonsaayman merged commit ae31394 into axios:v1.x Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants