Skip to content

Add presets to the tree-shaking options#4131

Merged
lukastaegert merged 7 commits into
masterfrom
treeshake-presets
Jun 16, 2021
Merged

Add presets to the tree-shaking options#4131
lukastaegert merged 7 commits into
masterfrom
treeshake-presets

Conversation

@lukastaegert

Copy link
Copy Markdown
Member

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:

Description

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.

@github-actions

github-actions Bot commented Jun 7, 2021

Copy link
Copy Markdown

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:
https://rollupjs.org/repl/?pr=4131

@codecov

codecov Bot commented Jun 11, 2021

Copy link
Copy Markdown

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
@lukastaegert lukastaegert deleted the treeshake-presets branch June 16, 2021 05:07
alicewriteswrongs added a commit to stenciljs/core that referenced this pull request Dec 7, 2022
alicewriteswrongs added a commit to stenciljs/core that referenced this pull request Jan 12, 2023
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.

1 participant