Add new treeshaking options - #1760
Merged
Merged
Conversation
* In the future, we might also check access in all kinds of "statements"
* TODO: clean up CLI
configurable via config file and CLI (resolves #1678) * Make ignoring property read side effects configurable via treeshake.propertyReadSideEffects via config file and CLI * Warning: Bad things can happen if you supply both --treeshake (or --no-treeshake) and e.g. --treeshake.pureExternalModules via CLI. Depending on the order of arguments either minimist crashes or the options have a currently unrecognized array format. Not sure more should be done here, maybe this is rather a documentation issue.
Contributor
|
Course-grained Are unknown globals still considered side effect free in all cases? |
Member
Author
|
Yes, for now you cannot use try..catch to check for the existence of globals 😉 As this is the previous behaviour and there are no open issues regarding this yet, I decided to postpone this for a later release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 PR will move
options.pureExternalModulestooptions.treeshake.pureExternalModulesand make it configurable via config file and also the CLI via--treeshake.pureExternalModules/--no-treeshake.pureExternalModules.It also adds the new
options.treeshake.propertyReadSideEffectswhich defaults totruebut can be disabled by setting it to false. If it is disabled, the following side-effects will not be detected andresultwill be removed if it is not used elsewhere in the code:accessing a getter with side-effects
accessing members of
nullorundefined:It is my guess that setting
options.treeshake.propertyReadSideEffects: falseor using--no-treeshake.propertyReadSideEffectswill work without problems in 95% of the use cases and can noticably reduce bundle size especially when passing around a lot of objects as function parameters.Also, a lot of unnecessary property access checks were removed in this PR which should give a slight speed boost.
Of course we should not forget to update the documentation once this is released.