@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 yourpackage.json:
Build Scripts
build
Builds code for production.- Minifies JavaScript
- Optimizes CSS
- Generates source maps
- Extracts CSS from JS
- Creates asset manifests
--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.- Auto-rebuilds on file changes
- Fast incremental builds
- Development source maps
--hot- Enable Fast Refresh--webpack-devtool- Custom source map type--no-watch- Build once without watching
Block Development
Automatic Entry Points
Scans forblock.json files and builds their scripts:
npm run build and get:
Custom Entry Points
Styling
Import styles in JavaScript:index.css- Editor stylesstyle-index.css- Frontend & editor styles
Code Quality
format
Formats code with Prettier.lint-js
Lints JavaScript and TypeScript with ESLint.lint-style
Lints CSS/SCSS with Stylelint.lint-pkg-json
Lintspackage.json files.
lint-md-docs
Lints markdown documentation.Testing
test-unit-js
Runs Jest unit tests.test-e2e
Runs Puppeteer end-to-end tests.test-playwright
Runs Playwright tests.Utilities
check-engines
Verifies Node.js and npm versions.check-licenses
Validates dependency licenses.--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.plugin-zip
Creates a plugin zip file.Configuration
Custom Webpack Config
Createwebpack.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
- Run debug command
- Open
chrome://inspect - Click “inspect” on your process
Best Practices
- Use Default Configs - Only customize when necessary
- Keep Scripts Updated - Regular updates bring improvements
- Test Before Build - Run linters and tests before production builds
- Use Source Maps - Enable for easier debugging
- Optimize Assets - Use production builds for deployment
- Version Control - Commit
package-lock.json - CI Integration - Run checks in continuous integration