Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Try/add dependency extraction plugin webpack #109

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ryanwelcher
Copy link
Contributor

@ryanwelcher ryanwelcher commented Feb 28, 2020

Description of the Change

This PR introduces the DependencyExtractionWebpackPlugin plugin that is used as part of the @wordpress/scripts package.

This plugin will convert calls to dependencies via import statements to access them on the appropriate global.

For example
import { registerPlugin } from '@wordpress/plugins

is converted to

var { registerPlugin } = wp.plugins

In addition, the plugin generates an assets.php file with dependencies and version number for each entry point.

The PR also makes changes to how the scaffold sets up the wp_enqueue_script calls to automate the process as much as possible.

Benefits

This plugin will automate generating a list of script dependencies and version numbers for each entry point in the Webpack config. This means that once it's been set up by the scaffold, engineers won't need to manually add dependencies to the array or manually bump the plugin version number to break caching.

Possible Drawbacks

To use this functionality, engineers must use import statements instead of pulling items from the global.

For example,const { registerPlugin } = wp.plugins becomesimport { registerPlugin } from '@wordpress/plugins.

This may seem counter-intuitive as we don't install those packages with the project.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Applicable Issues

Changelog Entry

@ryanwelcher ryanwelcher requested a review from timwright12 March 3, 2020 16:33
@samikeijonen
Copy link
Contributor

@ryanwelcher Like we discussed I like the concept. But I'd really really want to see CSS files in the version numbers also.

I've been using Webpack manifest plugin for the automated cache busting. It creates .json file which under some circumstances might not be the fastest file to read.

Copy link
Member

@nicholasio nicholasio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ryanwelcher can you fix the conflicts?

@timwright12
Copy link
Contributor

Do we need this in theme-scaffold as well or is it just for plugins?

@nicholasio
Copy link
Member

@timwright12 @ryanwelcher I feel like this can be useful for themes as well. I know for sure some projects ships custom blocks with themes

@samikeijonen
Copy link
Contributor

Do we need this when 10up scripts might be on the horizon?

@nicholasio
Copy link
Member

Do we need this when 10up scripts might be on the horizon?

10up scripts should abstract this away.

@ryanwelcher
Copy link
Contributor Author

@nicholasio @samikeijonen wondering if we can move this forward?

@samikeijonen: This change will make using any wp-* packages easier in JavaScript and save time by having dependencies managed automatically outside. Perhaps we can look at addressing the CSS versioning in separate issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants