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

Allow preservation of dynamic import with variable in CJS #4610

Closed
nzakas opened this issue Aug 17, 2022 · 4 comments · Fixed by #4647 or #4549
Closed

Allow preservation of dynamic import with variable in CJS #4610

nzakas opened this issue Aug 17, 2022 · 4 comments · Fixed by #4647 or #4549

Comments

@nzakas
Copy link

nzakas commented Aug 17, 2022

Feature Use Case

Because Node.js supports both require() and import() in CommonJS files, it would be helpful to be able to retain import() calls instead of translating them into require(). Here's a very simple example of what I'm trying to do:

https://rollupjs.org/repl/?version=2.71.1&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmV4cG9ydCUyMGZ1bmN0aW9uJTIwZG9JbXBvcnQoc3BlY2lmaWVyKSUyMCU3QiU1Q24lNUN0cmV0dXJuJTIwaW1wb3J0KHNwZWNpZmllciklM0IlNUNuJTdEJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlN0QlNUQlMkMlMjJvcHRpb25zJTIyJTNBJTdCJTIyZm9ybWF0JTIyJTNBJTIyY2pzJTIyJTJDJTIybmFtZSUyMiUzQSUyMm15QnVuZGxlJTIyJTJDJTIyYW1kJTIyJTNBJTdCJTIyaWQlMjIlM0ElMjIlMjIlN0QlMkMlMjJnbG9iYWxzJTIyJTNBJTdCJTdEJTdEJTJDJTIyZXhhbXBsZSUyMiUzQW51bGwlN0Q=

Feature Proposal

Add a preserveDynamicImports option that can be set to:

  • "all" - never rewrite import() regardless of the value passed in
  • "variable" - only preserve import() if it's used with a variable, otherwise overwrite as usual
  • "static" - only preserve import() when passed a constant
@lukastaegert
Copy link
Member

lukastaegert commented Oct 4, 2022

Fix at #4647, though with only a boolean switch (and on by default). For more fine-grained control, you can still use the plugin interface.

@nzakas
Copy link
Author

nzakas commented Oct 4, 2022

Nice, thank you!

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4647 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 npm install rollup@3.0.0-8 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4647 as part of rollup@3.0.0. You can test it via npm install rollup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants