chore: add sideEffects false to package.json #5025
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.