Production Build Pipeline for WordPress Plugins
Learn to configure a robust production build pipeline. Master minification, debug log removal, and artifact creation to ensure your plugin is ready for release.
Previously in this course, we covered protecting admin screens. Now that your Knowledge Base plugin is secure and functional, it's time to prepare it for the real world. A professional production build pipeline is the difference between a development experiment and a stable, performant plugin.
When you run npm run start during development, @wordpress/scripts creates unminified files with source maps for easy debugging. However, shipping these to production is a mistake: they are bloated, expose your development logic, and can slow down the WordPress admin interface.
The Principles of a Production Build
In a production environment, your goal is to minimize the payload size and remove any traces of development-specific code. This process involves three core pillars:
- Minification: Compressing JavaScript and CSS to reduce file size.
- Dead Code Elimination: Removing
console.logstatements, development-only warnings, and unused exports. - Asset Hashing/Optimization: Ensuring the browser fetches the latest version of your assets after an update.
Since we are using @wordpress/scripts, most of this is handled under the hood by Webpack. However, "just running build" isn't enough; you need to manage your environment variables and clean up your artifacts to prevent shipping junk to the end user.
Configuring the Build Pipeline
Your package.json file is the heart of your build process. When you run npm run build, Webpack triggers a production-ready compilation by default. Let's ensure your setup is optimized.
1. Stripping Debug Logs
While you might want console.log for debugging, it's unprofessional to leave them in production. You can automate their removal using a Babel plugin during the build.
Install the required dev dependency:
Bashnpm install babel-plugin-transform-remove-console --save-dev
Then, update your .babelrc.js (or add it if you don't have one):
JAVASCRIPTmodule.exports = { presets: [CE9178">'@wordpress/babel-preset-default'], plugins: [ [CE9178">'transform-remove-console', { exclude: [CE9178">'error', CE9178">'warn'] }] ] };
This configuration keeps your error logs visible for support tickets but silently strips standard console.log calls during your npm run build process.
2. Creating Production Artifacts
When you run npm run build, @wordpress/scripts generates files in the build/ directory. To maintain a clean production deployment, you must ensure your .gitignore file ignores the build/ folder during development but includes it in your release zip.
A common pitfall is including node_modules or src files in your final deployment zip. Use a tool like wp-scripts build to generate the assets, then use a script to package only the necessary files:
JSON// package.json snippet "scripts": { "build": "wp-scripts build", "zip": "zip -r knowledge-base-plugin.zip . -x '*.git*' 'node_modules/*' 'src/*' 'package.json' 'package-lock.json' 'webpack.config.js' '.eslintrc.js'" }
Hands-on Exercise: Cleaning the Pipeline
- Verify Build Output: Run
npm run buildand inspect thebuild/index.jsfile. Notice how it is a single, minified line of code. - Test Debug Removal: Add a
console.log('Testing debug removal')in your main React component. Run the build again and search the output file for that string. It should be gone. - Automate Cleanup: Ensure your
builddirectory is clean before every build by addingrm -rf buildto your build script inpackage.json.
Common Pitfalls
- Forgetting Source Maps: While you want minified code, keep your source maps (
.mapfiles) if you need to debug production errors, but ensure they aren't publicly accessible if you're concerned about intellectual property. - Hardcoded API URLs: Never hardcode your production API endpoints. Always use the localization techniques we discussed in earlier lessons to inject environment-specific variables.
- Ignoring Dependencies: If you use external npm packages, ensure they are correctly bundled. If you see "Module not found" errors in the browser console, your build configuration might be missing a required dependency in the
dependencies(notdevDependencies) section ofpackage.json.
Recap
A robust production build pipeline is essential for maintaining plugin performance and security. By integrating Babel plugins to strip console logs, automating your build cleanup, and carefully curating what gets packaged into your release, you ensure your plugin behaves predictably in every user's environment. Remember: development is about speed and flexibility, but production is about stability and efficiency.
Up next: Debugging React in the WordPress Admin
Work with me

Custom WordPress Plugin Development
Custom WordPress & WooCommerce plugins built to standard — by the developer behind a plugin with 5,000+ active installs and a SaaS with 10,000+ users.

Next.js Full-Stack Web App Development
A fast, SEO-ready full-stack web app built with Next.js 16 — from idea to deployed product, by an engineer who ships to production.