Skip to main content
The @wordpress/scripts package provides a collection of reusable scripts and configurations for WordPress development, eliminating the need to manage complex build tooling.

Installation

Requires Node.js LTS version (Active or Maintenance LTS).

Setup

Add scripts to your package.json:

Build Scripts

build

Builds code for production.
Features:
  • Minifies JavaScript
  • Optimizes CSS
  • Generates source maps
  • Extracts CSS from JS
  • Creates asset manifests
Options:
  • --webpack-bundle-analyzer - Visualize bundle sizes
  • --webpack-copy-php - Copy PHP files to output
  • --webpack-no-externals - Disable externals
  • --source-path=src - Custom source directory
  • --output-path=build - Custom output directory

start

Starts development build with watch mode.
Features:
  • Auto-rebuilds on file changes
  • Fast incremental builds
  • Development source maps
Options:
  • --hot - Enable Fast Refresh
  • --webpack-devtool - Custom source map type
  • --no-watch - Build once without watching

Block Development

Automatic Entry Points

Scans for block.json files and builds their scripts:
block.json:
Run npm run build and get:

Custom Entry Points

Styling

Import styles in JavaScript:
Output:
  • index.css - Editor styles
  • style-index.css - Frontend & editor styles

Code Quality

format

Formats code with Prettier.
Formats all supported files (JS, JSON, TypeScript, YAML). Custom paths:

lint-js

Lints JavaScript and TypeScript with ESLint.
Auto-fix:

lint-style

Lints CSS/SCSS with Stylelint.
Auto-fix:

lint-pkg-json

Lints package.json files.

lint-md-docs

Lints markdown documentation.

Testing

test-unit-js

Runs Jest unit tests.
Watch mode:
Coverage:
Specific tests:

test-e2e

Runs Puppeteer end-to-end tests.
Interactive mode:

test-playwright

Runs Playwright tests.
Debug mode:

Utilities

check-engines

Verifies Node.js and npm versions.

check-licenses

Validates dependency licenses.
Options:
  • --prod - Check production dependencies only
  • --dev - Check development dependencies only
  • --gpl2 - Validate GPL2 compatibility
  • --ignore=package1,package2 - Ignore specific packages

packages-update

Updates WordPress packages.
Specific version:

plugin-zip

Creates a plugin zip file.
Custom root folder:

Configuration

Custom Webpack Config

Create webpack.config.js:

Extending Webpack Config

Custom Babel Config

Create .babelrc.js:

ESLint Config

Create .eslintrc.js:

Prettier Config

Create .prettierrc.js:

Environment Variables

Development

Production

Custom Variables

WordPress Integration

Enqueue Built Assets

Asset File Format

Debugging

Debug Build

Debug Tests

Chrome DevTools

  1. Run debug command
  2. Open chrome://inspect
  3. Click “inspect” on your process

Best Practices

  1. Use Default Configs - Only customize when necessary
  2. Keep Scripts Updated - Regular updates bring improvements
  3. Test Before Build - Run linters and tests before production builds
  4. Use Source Maps - Enable for easier debugging
  5. Optimize Assets - Use production builds for deployment
  6. Version Control - Commit package-lock.json
  7. CI Integration - Run checks in continuous integration

Common Issues

Build Errors

Clear cache and rebuild:

Style Not Loading

Check import statement:

Dependencies Not Found

Ensure asset file is enqueued:

Learn More