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

[Feature]: preserve dynamic import in CJS #121

Closed
Timeless0911 opened this issue Aug 23, 2024 · 0 comments · Fixed by web-infra-dev/rspack#8414
Closed

[Feature]: preserve dynamic import in CJS #121

Timeless0911 opened this issue Aug 23, 2024 · 0 comments · Fixed by web-infra-dev/rspack#8414
Assignees

Comments

@Timeless0911
Copy link
Contributor

Timeless0911 commented Aug 23, 2024

What problem does this feature solve?

Input

const { parse } = await import("acorn");

Rslib CJS output

const { parse } = await Promise.resolve(/* import() */ ).then(__webpack_require__.t.bind(__webpack_require__, "acorn", 23));

What expected

const { parse } = await import("acorn");

We should support keep dynamic import in CJS output, thus avoid importing extra runtime code and keeping import existing.

What does the proposed API look like?

esbuild use supported and add an options dynamic-import to control it.

And in Modern.js Module, we deal like below

https://github.com/web-infra-dev/modern.js/blob/f624878a961da8e53a8181d8bf3591fe8c5da8b5/packages/solutions/module-tools/src/builder/esbuild/index.ts#L207-L209

supported: {
	'dynamic-import': buildType === 'bundle' || format !== 'cjs',
},
@Timeless0911 Timeless0911 changed the title [Feature]: keep dynamic import in CJS [Feature]: preserve dynamic import in CJS Aug 23, 2024
@fi3ework fi3ework self-assigned this Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants