-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Feature request: import(url, {importmap: {...}}) #8877
Copy link
Copy link
Closed
Labels
topic: imports/exportsImport maps, specifiers, imports, exportsImport maps, specifiers, imports, exports
Description
// hello.js
export const hello = (name) => console.log(`Hello ${name}!`);// test.js
import hello from './hello.js';
hello('world');// loader.js
const response = await fetch('./test.js');
let payload = await response.text();
// modify payload as necessary
const blob = new Blob([payload], {type: 'application/javascript'});
const url = URL.createObjectURL(blob); // blob:uuid
const module = await import(blob);
URL.revokeObjectURL(url);
globalThis.loaded = module;I would like to patch a script (e.g. add exports that expose unexported local variables) before actually importing it. Currently it requires the server to handle the patching. Alternatively the loader can replace leading ., .., / in static imports - this wouldn't work for dynamic imports though.
Instead, the line const module = await import(blob); could be replaced with:
const module = await import(blob, {
importmap: {
'./': new URL('./', location.href).href
}
});I'm not sure if this is the correct repo to report this issue - in that case please instruct me where I should report it instead.
Edit: I just found WICG/import-maps#92 so this issue potentially is a duplicate.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
topic: imports/exportsImport maps, specifiers, imports, exportsImport maps, specifiers, imports, exports