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 request: import(url, {importmap: {...}}) #8877

Closed
szmarczak opened this issue Feb 12, 2023 · 1 comment
Closed

Feature request: import(url, {importmap: {...}}) #8877

szmarczak opened this issue Feb 12, 2023 · 1 comment

Comments

@szmarczak
Copy link

szmarczak commented Feb 12, 2023

// 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.

@domenic
Copy link
Member

domenic commented Feb 15, 2023

Let's indeed track this in WICG/import-maps#92.

@domenic domenic closed this as completed Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants