Utilize webpack, @wordpress/scripts
, and wp-cli to manage WordPress assets.
Transforms your code according the configuration provided so it’s ready for production and optimized for the best performance. The output generated will be written to assets/build
. This script exits after producing a single build. For incremental builds, better suited for development, see the start
script.
It helps to enforce coding style guidelines for your files (JavaScript, YAML) by formatting source code in a consistent way.
Generates a .pot
translation file.
Helps enforce coding style guidelines for your JavaScript files.
Helps enforce standards for your package.json
files.
Helps enforce coding style guidelines for your style files.
Transforms your code according the configuration provided so it’s ready for development. The script will automatically rebuild if you make changes to the code, and you will see the build errors in the console. The output generated will be writen to assets/build
. For single builds, better suited for production, see the build
script.
The i18n
script requires wp-cli and the wp-cli/i18n-command
to be available in the current environment.
The build
and start
execute with --webpack-no-externals
to ensure @wordpress/*
packages are included within the bundle as they are not available to enqueue via wp-
script handles in WordPress < 5.0.
Remove --webpack-no-externals
from build
and start
to generate script asset files to manage @wordpress/*
dependencies and exclude them from the bundle.
To align with current practices of separate JavaScript and CSS webpack is set up to process entry points that contain only CSS. Style-only entry point names must be prefixed with style-
to ensure additional/unused .js
files are not emitted for the entry point.
To help reduce complexity within webpack.config.js
all emitted assets are output in a single assets/build
directory.
Existing plugins should have assets managed via wp_register_script()
or wp_enqueue_script()
so the location of the asset can be changed freely.
Because build
and start
generate different versions of files and emit different file sets the assets/build
directory is ignored and untracked. A direct clone of this repository requires users to run either npm run build
or npm run start
.
If asset tracking is required it is recommended to update the start
script to run in production mode to reduce the likely hood of merge conflicts (which will still happen frequently with tracked assets). This can be achieved with cross-env
; i.e cross-env NODE_ENV=production wp-scripts start
This project was created by (and is managed by) Sandhills Development, LLC, where we aim to craft superior experiences through ingenuity, with deep commitment to (and appreciation for) the human element.