Skip to content

Optimize our infrastructure for bundling external scripts #885

@felixarntz

Description

@felixarntz

Feature Description

We currently bundle several @wordpress/... packages manually, registering those only if they are not registered yet (WP < 5.0 without Gutenberg plugin). There are several problems with this:

  • They can have their own @wordpress/... dependencies, which we thus need to bundle as well, but figuring out those manually is tiresome and error-prone.
  • We have to currently manually maintain the versions of these assets in PHP code, which is just as painful.
  • We don't actually handle dependencies of dependencies in PHP at all, mostly because doing that would introduce even more manual work. Instead we just make all of them dependencies of everything, which technically works, but is not right and can cause in enqueuing more JS than we actually need for a certain area.

We need to improve our build scripts to automate these pieces, e.g. by actually relying on the information present in our package-lock.json. The same applies to the relevant PHP code in the Assets class, which should automatically consider the right dependencies for every dependency.

Maybe we can put this data into a simple array in PHP (like in https://core.trac.wordpress.org/browser/tags/5.3/src/wp-includes/script-loader.php#L271) that a build script could automatically write to, based on knowledge from package-lock.json. The PHP code would then just need to iterate over those items and register them in the correct version with the correct dependencies.

See #505 (comment) for more context on where this came up.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation Brief

Changelog entry

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions