Skip to content

Start using JavaScript Modules and Import Maps #36716

@gziolo

Description

@gziolo

What problem does this address?

Related WordPress Trac ticket: https://core.trac.wordpress.org/ticket/48654.

JavaScript Modules

Resource: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules

JavaScript has had modules for a long time. However, they were implemented via libraries, not built into the language. ES2015 is the first time that JavaScript has built-in modules. Older browsers like Internet Explorer 11 didn't support ES Modules. Earlier this year, WordPress dropped support for IE11, which opened the door to using ES Modules in the Gutenberg plugin and later in WordPress core. The most significant benefit of moving the codebase to modules is the possibility of using native browser techniques for async loading scripts

Import Maps

Resource: https://wicg.github.io/import-maps/

Import maps allow web pages to control the behavior of JavaScript imports.

There's native support for import maps in the latest versions of Chrome and Edge browsers, and a shim is available for any other browser that WordPress supports. In practical terms, import maps let use shared libraries by importing dependencies through a predefined list of aliases.

What is your proposed solution?

A long-term goal would be to use JavaScript modules and import maps for all Gutenberg plugin scripts. @youknowriad did some very promising initial explorations:

Metadata

Metadata

Labels

Developer ExperienceIdeas about improving block and theme developer experience[Status] In ProgressTracking issues with work in progress[Type] Build ToolingIssues or PRs related to build tooling

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions