@wordpress/scripts is a collection of reusable scripts tailored for WordPress development. Every tool comes with integrated recommended configuration, making it easy to set up modern JavaScript tooling without complex setup.
Installation
You only need to install one npm module:This package requires Node.js version 18.12.0 or above and npm version 8.19.2 or above.
Setup
Add the scripts to yourpackage.json file. This example demonstrates the most common capabilities:
package.json
Available Scripts
build
Transforms your code for production with optimized performance.Build Script Options
Build Script Options
Basic Usage
package.json
npm run build- builds the code for productionnpm run build:custom- builds with two entry points and custom output directorynpm run build:copy-php- builds and copies all PHP files to output directorynpm run build:custom-directory- builds using custom source directory
Available Flags
--webpack-bundle-analyzer- enables visualization for webpack output files--webpack-copy-php- copies all PHP files from source to output directory--webpack-no-externals- disables scripts’ assets generation and default externals--blocks-manifest- generates PHP file with block metadata from allblock.jsonfiles--source-path- customizes the source directory (default:src)--output-path- customizes the output directory (default:build)--experimental-modules- enables experimental support forviewScriptModulefield
Terminal
start
Transforms your code for development with automatic rebuilding on file changes.Start Script Options
Start Script Options
Basic Usage
package.json
npm start- starts build for developmentnpm run start:hot- starts with Fast Refresh (auto-reload on changes)npm run start:custom- starts with custom entry points and outputnpm run start:copy-php- starts and copies PHP files
Available Flags
--hot- enables Fast Refresh for automatic page reload (requiresSCRIPT_DEBUGenabled)--no-watch- starts build without starting the watcher--webpack-bundle-analyzer- enables visualization for webpack output files--webpack-copy-php- copies all PHP files from source to output--webpack-devtool- controls source map generation--webpack-no-externals- disables default externals--blocks-manifest- generates PHP file with block metadata--source-path- customizes source directory--output-path- customizes output directory
Terminal
format
Enforces coding style guidelines by formatting source code in a consistent way.lint-js
Enforces coding style guidelines for JavaScript and TypeScript files.lint-style
Enforces coding style guidelines for CSS, PCSS, and SCSS files.lint-pkg-json
Enforces standards forpackage.json files.
package.json
lint-md-docs
Enforces markdown standards for documentation files.package.json
test-unit-js
Launches the unit test runner using Jest.- Files with
.js,.jsx,.ts, or.tsxsuffix in__tests__folders - Files with
.js,.jsx,.ts, or.tsxsuffix intestfolders - Files with
.test.js,.test.jsx,.test.ts, or.test.tsxsuffix
test-playwright
Launches the Playwright end-to-end test runner..test or .spec suffix in the /specs folder.
Failed Test Artifacts:
When tests fail, snapshots are stored in the artifacts/ directory. You can customize this location:
test-e2e
Launches the end-to-end test runner using Jest and Puppeteer.- Files with
.js,.jsx,.ts, or.tsxsuffix inspecfolders - Files with
.spec.js,.spec.jsx,.spec.ts, or.spec.tsxsuffix
packages-update
Updates WordPress packages to their latest version.Packages Update Options
Packages Update Options
package.json
@wordpress/ and updates them.Available Flags
--dist-tag- specifies custom dist-tag (default:latest)
plugin-zip
Creates a zip file for a WordPress plugin.Plugin Zip Options
Plugin Zip Options
check-engines
Checks if current Node.js and npm versions match the required semantic version ranges.package.json
Terminal
check-licenses
Validates that all dependencies are compatible with the project’s license.Check Licenses Options
Check Licenses Options
package.json
Available Flags
--prodor--production- validates onlydependencies(notdevDependencies)--devor--development- validates onlydevDependencies(notdependencies)--gpl2- validates against GPLv2 license compatibility--ignore=a,b,c- comma-separated list of package names to ignore
build-blocks-manifest
Generates a PHP file containing block metadata from allblock.json files.
Generate the manifest
--input- specify input directory (default: ‘build’)--output- specify output file path (default: ‘build/blocks-manifest.php’)
Using Build Scripts
Entry Points
The simplest way to specify entry points:Automatic block.json Detection
The build script automatically scans thesrc directory for block.json files and uses their script fields as entry points:
block.json
Importing Styles
You can import styles in your JavaScript files:index.js
index.css- styles for the editor onlystyle-index.css- styles for both front-end and editor
Using SVG
Import SVG files as React components or URLs:Advanced Configuration
Custom Webpack Config
You can extend the default webpack config by creating awebpack.config.js file:
webpack.config.js
Debugging
Debugging Unit Tests
Debugging E2E Tests
--puppeteer-devtools option launches the browser with devtools already open for debugging.
Package Information
- Version: 31.5.0
- Node.js: >= 18.12.0
- npm: >= 8.19.2
- License: GPL-2.0-or-later
Related Packages
- @wordpress/env - Local WordPress environment
- @wordpress/create-block - Block scaffolding tool
- @wordpress/e2e-test-utils-playwright - E2E testing utilities