Make WordPress Core

Opened 6 months ago

Last modified 4 months ago

#61771 new enhancement

Script Modules: add the importmap's scopes key

Reported by: rosua's profile rosua Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.5
Component: Script Loader Keywords:
Focuses: javascript Cc:

Description

WP_Script_Modules::print_import_map() prints the script modules, but it only prints the imports key.

As per described on the https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap#import_map_json_representation, <script type="importmap"> element can have another optional key: scopes and integrity.

There's no means for a plugin to add scopes to be printed.
So, besides the wp_register_script_module() function, we need a function to register the scopes.

The use case of using scopes are typical when we are using CDN providers such as https://generator.jspm.io/

Change History (2)

#1 @gziolo
6 months ago

  • Focuses javascript added
  • Version changed from trunk to 6.5

#2 @jonsurrell
4 months ago

The scopes property is not printed at this time because WordPress has no use for it. It may in the future.

WordPress implements its own module system and tracks dependencies inside of WordPress. This could open the door to things like versioned dependencies. There are also some ideas to use scopes for localization data. But at this time the module system inside WordPress simply has no use for scopes.

Note: See TracTickets for help on using tickets.