Mahamudul Hasan Rubel
HomeBlogCoursesAboutProjectsSkillsExperiencePhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • Blog
  • Courses
  • About
  • Projects
  • Skills
  • Experience
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 28 of the Intermediate WordPress Plugins: REST API & React Admin course
WordPressJune 26, 20263 min read

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.

WordPressReactBuildWebpackDeploymentphpplugin-development

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:

  1. Minification: Compressing JavaScript and CSS to reduce file size.
  2. Dead Code Elimination: Removing console.log statements, development-only warnings, and unused exports.
  3. 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:

Bash
npm install babel-plugin-transform-remove-console --save-dev

Then, update your .babelrc.js (or add it if you don't have one):

JAVASCRIPT
module.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

  1. Verify Build Output: Run npm run build and inspect the build/index.js file. Notice how it is a single, minified line of code.
  2. 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.
  3. Automate Cleanup: Ensure your build directory is clean before every build by adding rm -rf build to your build script in package.json.

Common Pitfalls

  • Forgetting Source Maps: While you want minified code, keep your source maps (.map files) 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 (not devDependencies) section of package.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

Previous lessonProtecting Admin ScreensNext lesson Debugging React in the WordPress Admin
Back to Blog

Similar Posts

WordPressJune 26, 20263 min read

Internationalization in React: WordPress Translation for Plugins

Learn how to implement i18n in your React admin screens. Master __() and _x() in JavaScript to make your Knowledge Base plugin truly translation-ready.

Read more
WordPressJune 26, 20264 min read

Debugging React in the WordPress Admin: A Practical Guide

Debugging React in the WordPress admin requires a systematic approach. Learn to inspect component hierarchies, trace data store actions, and analyze API traffic.

Part of the course

Intermediate WordPress Plugins: REST API & React Admin

intermediate · Lesson 28 of 45

  1. 1

    Setting up the WordPress Development Environment

    3 min
  2. 2

    Introduction to @wordpress/scripts

    3 min
  3. 3

    Configuring ESLint and Prettier

    3 min
Read more
WordPressJune 26, 20263 min read

Input Validation and Error Handling for WordPress REST API & React

Learn to build robust input validation for your WordPress plugin. Discover how to provide instant client-side feedback and handle server-side errors gracefully.

Read more
4

Localizing Data for JavaScript

3 min
  • 5

    Anatomy of a REST API Endpoint

    3 min
  • 6

    Implementing REST API Permission Callbacks

    3 min
  • 7

    Handling GET Requests in REST API

    3 min
  • 8

    Validating and Sanitizing API Arguments

    4 min
  • 9

    Creating POST Endpoints for Data Submission

    3 min
  • 10

    Updating Existing API Resources

    3 min
  • 11

    Handling Asynchronous State in React

    3 min
  • 12

    Building the Knowledge Base Service Layer

    3 min
  • 13

    Scaffolding the React Admin Dashboard

    3 min
  • 14

    Working with @wordpress/components

    3 min
  • 15

    Creating a React Form for Submissions

    3 min
  • 16

    Implementing CRUD in the Admin UI

    3 min
  • 17

    Understanding WordPress Data Store Architecture

    4 min
  • 18

    Registering a Custom Data Store

    3 min
  • 19

    Writing Selectors for Data Access

    3 min
  • 20

    Defining Actions and Reducers

    3 min
  • 21

    Implementing Resolvers for Data Fetching

    3 min
  • 22

    Optimizing Performance with Selectors

    3 min
  • 23

    Handling Complex State Dependencies

    4 min
  • 24

    Implementing Nonce Verification

    4 min
  • 25

    Advanced Sanitization Techniques

    3 min
  • 26

    Input Validation and Error Handling

    3 min
  • 27

    Protecting Admin Screens

    3 min
  • 28

    Production Build Pipeline

    3 min
  • 29

    Debugging React in the WordPress Admin

    4 min
  • 30

    Building Search and Filter Functionality

    3 min
  • 31

    Internationalization in React

    3 min
  • 32

    Managing File Uploads via REST API

    3 min
  • 33

    Optimizing API Response Times

    Coming soon
  • 34

    Working with Date and Time in React

    Coming soon
  • 35

    Implementing Drag-and-Drop Sorting

    Coming soon
  • 36

    Creating Custom Hooks for API Logic

    Coming soon
  • 37

    Integrating with Gutenberg Blocks

    Coming soon
  • 38

    Handling Conflict Resolution

    Coming soon
  • 39

    Building a Modal Confirmation System

    Coming soon
  • 40

    Implementing Activity Logging

    Coming soon
  • 41

    Using Webpack Aliases

    Coming soon
  • 42

    Unit Testing API Endpoints

    Coming soon
  • 43

    Unit Testing React Components

    Coming soon
  • 44

    Handling Large Datasets with GraphQL

    Coming soon
  • 45

    Implementing Real-time Updates with Web

    Coming soon
  • View full course