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

Avoid dynamic facade chunks #3535

Merged
merged 7 commits into from May 6, 2020
Merged

Avoid dynamic facade chunks #3535

merged 7 commits into from May 6, 2020

Conversation

lukastaegert
Copy link
Member

@lukastaegert lukastaegert commented May 5, 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 #3125

Description

This will prevent the creation of facade chunks for dynamic imports to reduce the number of chunks. Previously, especially for more complex bundles, most dynamic imports would create an additional chunk that just contained re-exports to create the correct namespace for the import.

With this PR, this will no longer happen:

  • if the imported chunk itself does not export anything that is not part of the namespace, it will become the facade chunk (this was already the old logic)
  • if an entry point has a facade chunk due to preserveEntrySignatures: 'strict', this one will be used by the import (this was already the old logic as well)
  • otherwise, a dynamic namespace object will be created inside the chunk and exported as a named export, then it will be unwrapped by the importing chunk:

I think this will a huge improvement to the chunking experience.

Additionally, this will also change the code generated for CommonJS dynamic imports from (REPL)

new Promise(function (resolve) { resolve(require('./dynamic.js')); });

to (REPL)

Promise.resolve().then(function () { return require('./dynamic.js'); });

This will fix a bug where the contents of the imported file are executed synchronously before the current synchronous block has finished executing. This could cause nasty issues when a dynamic import directly requires the currently executing file.

@lukastaegert lukastaegert mentioned this pull request May 5, 2020
@rollup-bot
Copy link
Collaborator

rollup-bot commented May 5, 2020

Thank you for your contribution! ❤️

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

npm install rollup/rollup#avoid-dynamic-facades

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

@codecov
Copy link

codecov bot commented May 5, 2020

Codecov Report

Merging #3535 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3535      +/-   ##
==========================================
+ Coverage   96.22%   96.24%   +0.01%     
==========================================
  Files         176      176              
  Lines        5984     6014      +30     
  Branches     1765     1773       +8     
==========================================
+ Hits         5758     5788      +30     
  Misses        112      112              
  Partials      114      114              
Impacted Files Coverage Δ
src/ast/variables/Variable.ts 100.00% <ø> (ø)
src/rollup/rollup.ts 100.00% <ø> (ø)
src/Chunk.ts 99.78% <100.00%> (+0.01%) ⬆️
src/Module.ts 98.89% <100.00%> (-0.02%) ⬇️
src/ast/nodes/ImportExpression.ts 100.00% <100.00%> (ø)
src/ast/variables/NamespaceVariable.ts 100.00% <100.00%> (ø)
src/utils/deconflictChunk.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 468010b...bf33923. Read the comment docs.

@lukastaegert lukastaegert marked this pull request as ready for review May 6, 2020 04:43
@lukastaegert
Copy link
Member Author

This is ready to be merged now

@lukastaegert lukastaegert merged commit f514c76 into master May 6, 2020
@lukastaegert lukastaegert deleted the avoid-dynamic-facades branch May 6, 2020 04:58
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.

Prevent facade creation for dynamic chunks
2 participants