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

Support dynamic import in bundles. #4561

Merged
merged 3 commits into from
Apr 2, 2020

Conversation

kitsonk
Copy link
Contributor

@kitsonk kitsonk commented Apr 1, 2020

Fixes #4062

@ry
Copy link
Member

ry commented Apr 1, 2020

Why would someone want to have a static module specifier in dynamic import? Wouldn't they just use a normal import?

@kitsonk
Copy link
Contributor Author

kitsonk commented Apr 1, 2020

@ry conditional imports. You might include two different modules, but only load one at runtime. Basically this PR looks to see if the dynamic import module specifier is in the bundle, if it is, it uses that, otherwise passes it to import().

I realised there is a defect with this, as I don't instantiate a dynamically imported module property. The test works because the module I am importing doesn't have imports itself.

@kitsonk
Copy link
Contributor Author

kitsonk commented Apr 2, 2020

@ry ok, everything is fixed now.

Also, again a practical example:

const myAPIs = "Deno" in globalThis ? await import("./deno_api.ts") : await import("./browser_api.ts");

The compiler would add both deno_api.ts and browser_api.ts to the bundle (and actually set the type of myAPIs for type checking), but at runtime, only the correct module would be instantiated.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ry ry merged commit 2e24385 into denoland:master Apr 2, 2020
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.

[bug] dynamic import not working in bundles
2 participants