-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 add importmap script into head #4168
Comments
We can move that above other scripts by default maybe 👀 But having an order attribute might be more customizable. |
I think importmap should have a special handling and be directly added to the HTML at compile time (even in dev mode) and not added at runtime by When declaring a head element with
Which roughly transletes to
Has I understand it, importmap scripts cannot be added dynamically to the page. |
Relevant vite issue vitejs/vite#15192 A working solution is privided here : use a Vite plugin to inject the importmap inside the HTML. Example: export default defineConfig({
vite: {
plugins: [
{
name: 'html-transform',
transformIndexHtml(html) {
return html.replace('</head>', `
<script type="importmap">
{
"imports": {
.....
}
}
</script>
</head>`,
);
},
},
],
},
}); |
This is not working when |
Vitepress transformHtml(html) {
return html.replace('<head>', `<head>${importmap}`);
}, See here for complete implementation (bottom of the file) |
Is your feature request related to a problem? Please describe.
I want to add a script which type is 'importmap' into top of head, but all solution is failed. The official custom head config, will add script into end of head, this causes 'importmap' to fail to work.
Describe the solution you'd like
Describe alternatives you've considered
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: