-
-
Notifications
You must be signed in to change notification settings - Fork 298
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
[@web/dev-server-import-maps] Support for external import maps #2562
Comments
I've quickly patched the https://github.com/modernweb-dev/web/blob/master/packages/dev-server-import-maps/src/importMapsPlugin.ts#L121-L123 file, and it works! if (getAttribute(importMapScript, 'src')) {
- throw new Error('Import maps with a "src" attribute are not yet supported.');
+ const importMapPath = getAttribute(importMapScript, 'src');
+ const content = fs.readFileSync(importMapPath, 'utf8');
+ setTextContent(importMapScript, content);
+ removeAttribute(importMapScript, 'src');
} |
There might be a good reasons not to support From MDN https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap
Pay attention that At the same time, in the proposal I see the
Is there actually a consensus about this feature? In general we try not to add non-standard features, at least without a good confidence that they will become a standard and got enough support from browser vendors and other stakeholders. In this case I can imagine the |
See WICG/import-maps#235. @domenic wrote that external import maps will be implemented in Chromium, but can't give an ETA. Import maps can be very large and generated by third-party tools. Inline them manually into HTML is a poor DX. |
Thanks for sharing this link, it does shed some light on this. I have a bad feeling about the future of this feature given it's taking already more than 3 years for Chrome and others to implement it, so I'd rather not run ahead of the locomotive. |
Not sure if we had a practice before in Modern Web with experimental feature plugins, maybe that can be a sort of in the middle solution. Curious if @thepassle @Westbrook @koddsson have an idea? You can also make your own plugin meanwhile and publish it yourself. |
I've used https://github.com/jsenv/importmap-node-module to generate import map for my project.
After that I've tried to use the generated
project.importmap
file:<html> <head> + <script type="importmap" src="./project.importmap"></script> </head> <body> <script type="module"> import lodash from "lodash" </script> </body> </html>
I've used http-server npm package to serve my project "as is" without any transformations. But I get the
External import maps are not yet supported.
error in the latest version of Chrome.So I've tried to use the
@web/dev-server
with@web/dev-server-import-maps
plugin, but get theImport maps with a "src" attribute are not yet supported.
error. See https://github.com/modernweb-dev/web/blob/master/packages/dev-server-import-maps/src/importMapsPlugin.ts#L122.Since import maps are now supported natively cross-browser, the need for the
@web/dev-server-import-maps
plugin is reduced. But if it supported external import maps, its value would immediately increase.As far as I understand, all that's needed is to inline the content of the external import map file into
<script type="importmap"></script>
tag inside HTML.The text was updated successfully, but these errors were encountered: