Skip to main content
@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 your package.json file. This example demonstrates the most common capabilities:
package.json
You can now run these commands using npm:

Available Scripts

build

Transforms your code for production with optimized performance.

Basic Usage

package.json
Run the scripts:
  • npm run build - builds the code for production
  • npm run build:custom - builds with two entry points and custom output directory
  • npm run build:copy-php - builds and copies all PHP files to output directory
  • npm 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 all block.json files
  • --source-path - customizes the source directory (default: src)
  • --output-path - customizes the output directory (default: build)
  • --experimental-modules - enables experimental support for viewScriptModule field
Example Output:
Terminal

start

Transforms your code for development with automatic rebuilding on file changes.

Basic Usage

package.json
Run the scripts:
  • npm start - starts build for development
  • npm run start:hot - starts with Fast Refresh (auto-reload on changes)
  • npm run start:custom - starts with custom entry points and output
  • npm run start:copy-php - starts and copies PHP files

Available Flags

  • --hot - enables Fast Refresh for automatic page reload (requires SCRIPT_DEBUG enabled)
  • --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
Example Output:
Terminal

format

Enforces coding style guidelines by formatting source code in a consistent way.
1

Format entire project

Formats all files in the project (JavaScript, JSON, TypeScript, YAML).
2

Format specific directory

Formats only files in the src directory.
3

Customize ignored files

Create a .prettierignore file in your project root:
.prettierignore

lint-js

Enforces coding style guidelines for JavaScript and TypeScript files.
Uses ESLint with the @wordpress/eslint-plugin configuration.

lint-style

Enforces coding style guidelines for CSS, PCSS, and SCSS files.
Uses Stylelint with the @wordpress/stylelint-config configuration per WordPress CSS Coding Standards.

lint-pkg-json

Enforces standards for package.json files.
package.json
Uses npm-package-json-lint with the @wordpress/npm-package-json-lint-config configuration.

lint-md-docs

Enforces markdown standards for documentation files.
package.json
Uses markdownlint to enforce WordPress documentation standards.

test-unit-js

Launches the unit test runner using Jest.
Jest looks for test files with these naming conventions:
  • Files with .js, .jsx, .ts, or .tsx suffix in __tests__ folders
  • Files with .js, .jsx, .ts, or .tsx suffix in test folders
  • Files with .test.js, .test.jsx, .test.ts, or .test.tsx suffix

test-playwright

Launches the Playwright end-to-end test runner.
By default, looks for test files with .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.
Jest looks for e2e test files:
  • Files with .js, .jsx, .ts, or .tsx suffix in spec folders
  • Files with .spec.js, .spec.jsx, .spec.ts, or .spec.tsx suffix

packages-update

Updates WordPress packages to their latest version.
package.json
The script detects dependencies starting with @wordpress/ and updates them.

Available Flags

  • --dist-tag - specifies custom dist-tag (default: latest)
Example:

plugin-zip

Creates a zip file for a WordPress plugin.
package.json

Available Flags

  • --root-folder - adds custom root folder to the zip file
  • --no-root-folder - creates zip with no folder inside
Examples:
Terminal

Customize Files

You can customize included files using the files field in package.json:
package.json

check-engines

Checks if current Node.js and npm versions match the required semantic version ranges.
package.json
Example Output:
Terminal

check-licenses

Validates that all dependencies are compatible with the project’s license.
package.json

Available Flags

  • --prod or --production - validates only dependencies (not devDependencies)
  • --dev or --development - validates only devDependencies (not dependencies)
  • --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 all block.json files.
1

Generate the manifest

Options:
  • --input - specify input directory (default: ‘build’)
  • --output - specify output file path (default: ‘build/blocks-manifest.php’)
2

Use in your plugin

Or register all blocks automatically (WordPress 6.8+):
This improves performance when registering multiple block types (requires WordPress 6.7+).

Using Build Scripts

Entry Points

The simplest way to specify entry points:

Automatic block.json Detection

The build script automatically scans the src directory for block.json files and uses their script fields as entry points:
block.json
Then simply run:

Importing Styles

You can import styles in your JavaScript files:
index.js
The build generates:
  1. index.css - styles for the editor only
  2. style-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 a webpack.config.js file:
webpack.config.js
Continue using wp-scripts commands (not webpack directly) and check the CHANGELOG before upgrading.

Debugging

Debugging Unit Tests

1

Add debugger statement

2

Run with inspector

3

Open Chrome DevTools

  1. Open about:inspect in Google Chrome
  2. Click “inspect” on your process
  3. Click resume button to continue execution

Debugging E2E Tests

The --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