-
-
Notifications
You must be signed in to change notification settings - Fork 939
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
Can add sideEffects: false
to package.json
#2335
Comments
What are the requirements for our code to use that safely? |
In web development, intercept API requests and use faker return random data. However, in production mode, interception is not necessary. |
Sorry, thats not what I meant. |
Because removing code during tree shaking is a risky behavior, if a package not specify sideEffects as false, bundlers like rollup will assume that the code in this package has side effects. In order to ensure the proper functioning of the code, rollup will retain them during tree shaking. Wether to set However, I am not familiar with the code of faker, so I cannot make a judgment. |
What is considered a side effect? A Faker internally shared global? Or does side effect require interaction with a third party library like registering a plugin in prettier? |
I think for faker, the main question is wether it modifies window or global objects. Or wether it introduced other packages with side effects.
I think if my code doesn't use any methods exported by faker, removing faker from build output would not break the program. Therefore, it can be considered as having no side effects. |
even if harmless, if this affects the behavior of the bundler it should probably be considered a semver-major change. |
Is it possible to add sideEffects: false in the package.json file?
This can help rollup with tree shaking.
For example, I want to use fakerjs in development mode but remove it in production mode.
When sideEffects is not set to false, even if the condition of if statement is false, faker will still be bundled together.
The text was updated successfully, but these errors were encountered: