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

Add presets to the tree-shaking options #4131

merged 7 commits into from Jun 16, 2021

Add presets to the tree-shaking options #4131

merged 7 commits into from Jun 16, 2021


Copy link

@lukastaegert lukastaegert commented Jun 7, 2021

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:


As the number of tree shaking options is growing, this will provide the user to additionally choose from three presets: safest, smallest and recommended.

The differences are that while smallest uses the most aggressive setting everywhere and safest uses the most conservative, recommended will be conservative on most settings but may swallow some syntactic errors. At the moment, it will swallow errors from accessing unknown global variables, but in the future this may extend to accessing const/let variables before they are initialized.

You can use if like this:

export default {
  treeshake: 'safest',
  // ...

There is also an object form that allows using a preset while overriding some values:

export default {
  treeshake: {
    preset: 'smallest',
    propertyReadSideEffects: true
  // ...

From the CLI, you use it like this

rollup -c --treeshake smallest

Using a preset from the CLI will of course override any values in the config file.

Copy link

@github-actions github-actions bot commented Jun 7, 2021

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#treeshake-presets

or load it into the REPL:

Copy link

@codecov codecov bot commented Jun 11, 2021

Codecov Report

Merging #4131 (d8ad9ac) into master (7212516) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4131   +/-   ##
  Coverage   98.12%   98.13%           
  Files         201      201           
  Lines        7090     7114   +24     
  Branches     2074     2081    +7     
+ Hits         6957     6981   +24     
  Misses         64       64           
  Partials       69       69           
Impacted Files Coverage Δ
src/rollup/rollup.ts 100.00% <ø> (ø)
src/utils/options/mergeOptions.ts 100.00% <100.00%> (ø)
src/utils/options/normalizeInputOptions.ts 100.00% <100.00%> (ø)
src/utils/options/normalizeOutputOptions.ts 100.00% <100.00%> (ø)
src/utils/options/options.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7212516...d8ad9ac. Read the comment docs.

@lukastaegert lukastaegert merged commit 86e8510 into master Jun 16, 2021
10 checks passed
@lukastaegert lukastaegert deleted the treeshake-presets branch Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

1 participant