-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[5.0] ESM importmap support #40714
[5.0] ESM importmap support #40714
Conversation
Hats off Fedir! This is the most important feature for j5 for the modern js… |
I have added |
@Fedik Is it possible to use |
Yes, can be done |
Still not sure why we need importmaponly parameter, maybe I have not enough understanding that someone needs both. |
Not allowing both will be an unneeded limitation. That why I think that we need a way to have it both, without duplicating the asset declaration. It can be other way around, when |
Hmhm, or maybe I will remove it. Duplicated asset with "cross dependency" also can work to allow both. |
I have removed |
ok I would say we have a MVP here and can merge it do we have a test case for it which where we can use it in core? I think codemirror maybe too complicated as simple test suite? |
@HLeithner #41018 is a more realistic example |
Also probably can be Bootstrap js. |
Would be great, not sure if this is possible in a b/c way? |
it’s backward compatible. The only problem with switching to import maps is the extra polyfill cost and the fact that to get the es5 scripts there’s a need for some changes in the build tools. Assuming that the es5 will be dropped in v5 the only consideration is the polyfill cost. btw is there a plan to merge the pr for the drop of es5? |
All the .es6.js that have an import can be switched to import maps: guided tours, keyboard short cuts, choices custom element, form validator, etc Also it’s an easy task, change the import, add the module to be imported to the dependencies and add an entry to the assets json. Job done! |
yes is planned, wasn't able to test it personally yet |
Thanks, I tested it and merged it for now and hope for more tests in alpha2, also I think we should remove the default polyfill |
PR for manual joomla/Manual#134 |
@Fedik the nonce attribute for the CSP is respected as far as I understand the Also shouldn't we disallow some other attributes there, ie async, defer, noscript, etc? |
Yeap CSP should be there for
For wich case? For script with |
Summary of Changes
This PR add support for <script type="importmap"> in to WebAsset manager.
The browser support is limited to only 2023 year version, but that should not stop us.
As for now, I have added a polyfill.
helper method to work around browser support for "top level" imports.What changed:
joomla.asset.json
added next properties for "script" asset:importmap
boolean, whether the element should be added to "importmap";importmapOnly
boolean, whether the element should be ONLY in "importmap", and do not render it as<script>
;importmapName
string, optional, custom module name, example when asset namefoo
, and module name is@foo
;Fallback for orlder browser
Uses
es-module-shims
polyfill.Because of browser support I have addedesm-map
asset, wich providejoomlaESMap()
function to resolve module to URL when "importmap" not supported.Untill browser support will get better we should use the import as following:PS: I know about polyfill, but I do not like how that works.Testing Instructions
Apply path, run
npm install
.Create 2 js file:
media/system/js/test-module.js
with content:media/system/js/test.js
with content:Add them to
media/system/joomla.asset.json
:In index.php of the template, enable this "testing asset" with
$wa->useScript('test');
Open the site in browser, and look in browser console.
You should get console log of Object from "test-module".
Link
schema
forjoomla.asset.json
Update asset schema: importmap properties schemas#17