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

Expose importer path to dynamicImportFunction #3444

Closed
LarsDenBakker opened this issue Mar 15, 2020 · 4 comments · Fixed by #3449
Closed

Expose importer path to dynamicImportFunction #3444

LarsDenBakker opened this issue Mar 15, 2020 · 4 comments · Fixed by #3449

Comments

@LarsDenBakker
Copy link
Contributor

Feature Use Case

Native dynamic imports resolve paths relative to the importing module. When implementing a dynamic import polyfill, it would be ideal to implement the same logic.

Feature Proposal

When using dynamicImportFunction, only the imported module path is exposed. It would be great if the importing module URL could be exposed as well.

So instead of:

importShim('./foo.js');

Do:

importShim('./foo', import.meta.url);

A dynamic import polyfill could then resolve the URL somewhat like this:

window.importShim = (id, importer) => {
  const importPath = new URL(id, importer);
  // ... rest of the logic
});
@LarsDenBakker
Copy link
Contributor Author

See GoogleChromeLabs/dynamic-import-polyfill#8 why this is necessary for polyfills.

@lukastaegert
Copy link
Member

I see your point, but I am still undecided. Another approach I am considering is to add a new renderDynamicImport hook that has the ability to both transform the import function and the arguments, and especially add additional ones. Still, your suggestion makes sense as a default when a dynamicImportFunction is supplied.

@lukastaegert
Copy link
Member

Here is the renderDynamicImport hook, including an example how to solve your issue: #3449

My preference would be to go with this hook and otherwise deprecate the dynamicImportFunction with the next major version.

@LarsDenBakker
Copy link
Contributor Author

Deprecating dynamicImportFunction sounds like the right approach here!

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 a pull request may close this issue.

2 participants