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
[v3.0] Keep dynamic imports in CommonJS output #4647
Conversation
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install rollup/rollup#rollup-3-cjs-dynamic-import or load it into the REPL: |
Codecov Report
@@ Coverage Diff @@
## release-3.0.0 #4647 +/- ##
================================================
Coverage ? 98.97%
================================================
Files ? 213
Lines ? 7485
Branches ? 2115
================================================
Hits ? 7408
Misses ? 23
Partials ? 54
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
24ededd
to
b46330e
Compare
f75b690
to
a5df4a1
Compare
* Support dynamic imports in cjs output and make default * Add documentation * Also use import for unresolvable dynamic imports * Extend CLI docs
This PR has been released as part of rollup@3.0.0-8. Note that this is a pre-release, so to test it, you need to install Rollup via |
* Support dynamic imports in cjs output and make default * Add documentation * Also use import for unresolvable dynamic imports * Extend CLI docs
This PR has been released as part of rollup@3.0.0. You can test it via |
cf rollup/rollup#4647 This fixes e2e tests on Windows.
cf rollup/rollup#4647 This fixes e2e tests on Windows.
Bumps [rollup](https://github.com/rollup/rollup) from 2.79.0 to 3.20.2. The only difference in artifacts is in the CJS file. The dynamic import of superagent is no longer rewritten as require (rollup/rollup#4647). We can turn that off with rollup config, but it should work with this change since dynamic import in CJS has been available since node version 9. Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
BREAKING CHANGE: We keep external dynamic imports in CommonJS output by default as
import()
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
In order to complete the Node ESM story in Rollup 3, I decided to add this last feature to Rollup 3. This will by default keep external (and only those) dynamic imports in CommonJS output as
import(…)
to support ESM interop. You can deactivate this behavior via a new optiondynamicImportInCjs: false
, which will activate the old rewriting behavior.output.dynamicImportInCjs
Type:
boolean
CLI:
--dynamicImportInCjs
/--no-dynamicImportInCjs
Default:
true
While CommonJS output originally supported only
require(…)
to import dependencies, recent Node versions also started to supportimport(…)
, which is the only way to import ES modules from CommonJS files. If this option istrue
, which is the default, Rollup will keep external dynamic imports asimport(…)
expressions in CommonJS output. Set this tofalse
to rewrite dynamic imports usingrequire(…)
syntax.