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

Disable treeshaking per module #3663

Merged
merged 4 commits into from Jul 7, 2020
Merged

Conversation

lukastaegert
Copy link
Member

@lukastaegert lukastaegert commented Jul 7, 2020

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:
Resolves #3655, resolves #3651

Description

This allows to disable tree-shaking on a per-module basis by setting moduleSideEffects to "no-treeshake" in https://rollupjs.org/guide/en/#resolveid, https://rollupjs.org/guide/en/#load or https://rollupjs.org/guide/en/#transform.

Besides the obvious effect, this will also make sure that this module is always included in one of the generated chunks, even if the module is empty. The important use-case here is CSS (or in general asset) import handling when the imports should later be associated with a specific chunk:

  1. The plugin that handles e.g. import 'foo.css' returns {code: '', moduleSideEffects: 'no-treeshake'} in its load hook for "foo.css".
  2. Then in generateBundle, the plugin can scan the modules properties in the chunks of the passed bundle object for our module foo.css and associate the actually generated CSS correctly with the given chunk.

@rollup-bot
Copy link
Collaborator

rollup-bot commented Jul 7, 2020

Thank you for your contribution! ❤️

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

npm install rollup/rollup#disable-module-treeshaking

or load it into the REPL:
https://rollupjs.org/repl/?circleci=12276

@codecov
Copy link

codecov bot commented Jul 7, 2020

Codecov Report

Merging #3663 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3663   +/-   ##
=======================================
  Coverage   96.71%   96.71%           
=======================================
  Files         183      183           
  Lines        6299     6303    +4     
  Branches     1834     1835    +1     
=======================================
+ Hits         6092     6096    +4     
  Misses        105      105           
  Partials      102      102           
Impacted Files Coverage Δ
src/ExternalModule.ts 97.95% <ø> (ø)
src/Graph.ts 100.00% <100.00%> (ø)
src/Module.ts 100.00% <100.00%> (ø)
src/ModuleLoader.ts 100.00% <100.00%> (ø)
src/utils/transform.ts 98.43% <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 974492f...2df12c6. Read the comment docs.

@lukastaegert lukastaegert merged commit 9755fc7 into master Jul 7, 2020
@lukastaegert lukastaegert deleted the disable-module-treeshaking branch July 7, 2020 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants