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
feat: add dynamicImportFunction option #2723
feat: add dynamicImportFunction option #2723
Conversation
This option allows users of `es` format to rename the `import()` function, which right now has mixed support in browsers. By allowing this function to be renamed we can have polyfills (which cannot use the reserved `import` keyword but could go by a different name like `importModule`).
ee6b1f2
to
9a17e68
Compare
Thanks, I like the feature, implementation looks also fine (though there is still an option list in the tests that needs to be adjusted I assume). Some thoughts:
|
…mportfunction-option # Conflicts: # src/Chunk.ts # test/misc/optionList.js
Okay @lukastaegert I believe this addresses your points. Thanks for fixing the tests 😄 |
…ption' into feat-add-dynamicimportfunction-option
Nice one, thanks a lot, especially for the link to the polyfill! |
Why is it limited to I have a use case for thins for if(typeof fetch === 'undefined'){ // in node shim JSON modules with imported require
const createRequire = await import('module').then(m=>m.createRequire);
const require = createRequire(import.meta.url);
currentVersion = require('../../package.json').version;
} else { // in browser shim with fetch
currentVersion = await fetch('../../package.json')
.then(response => response.json())
.then(json => json.version);
} On Node it runs flawlessly, in modern browsers as well, but old Edge is throwing a I would like to use |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
N/A
Description
This option allows users of
esm
format to rename theimport()
function, which right now has mixed support in browsers. By allowing this function to be renamed we can have polyfills (which cannot use the reservedimport
keyword but could go by a different name likeimportModule
).Right now if we chose to use
esm
format, and use dynamic imports, then the output source text uses theimport()
function - this fails in browsers that don't supportimport()
. By adding this option, and renamingimport()
to something else, we have a chance at using dynamic imports before all browsrs support them.