MagicChecklists Build Process
Documents a React build pipeline inside a WordPress plugin, covering dev, production, and distribution workflows.
What this file does
Documents a React build pipeline inside a WordPress plugin, covering dev, production, and distribution workflows.
When to use it
- You are building a React frontend inside a WordPress plugin
- You need a Vite-based dev server with HMR for WordPress admin
- You want automated version syncing between package.json and PHP
- You need a build script that produces a distributable plugin zip
Assumes this stack
MagicChecklists Build Process
This document explains how the React build process works for the MagicChecklists WordPress plugin.
Development vs Production
The plugin automatically detects whether it should run in development or production mode:
- Development Mode: When
npm run devis running on localhost:3000 - Production Mode: When using built files from the
dist/directory
Development Mode
npm run dev
Features:
- Hot Module Replacement (HMR)
- React Fast Refresh
- Real-time code updates
- Source maps for debugging
- Loads scripts directly from Vite dev server
Production Mode
npm run build
Features:
- Optimized bundles with chunking
- Minified CSS and JavaScript
- Tree-shaking for smaller bundle sizes
- Vendor chunk separation
- ES modules with proper loading order
Plugin Distribution Build
For creating a production-ready plugin zip file:
npm run build-plugin
This script will:
- โ
Check version consistency between
package.jsonandmagicchecklists.php - ๐ง Automatically sync versions if they don't match
- ๐จ Run
npm run buildto create optimized assets - ๐ Copy all necessary plugin files to a build directory
- ๐ฆ Create a zip file ready for distribution
- ๐งน Clean up temporary files
Output: magicchecklists-[version].zip in the project root
Manual Version Sync
If you need to sync versions manually:
npm run version-sync
This ensures the version in package.json matches the version in magicchecklists.php.
File Structure
Development Files (Not Included in Distribution)
src/- React source filesnode_modules/- Dependenciesvite.config.js- Build configurationpackage.json- Node.js dependencies- Development configuration files
Production Files (Included in Distribution)
dist/- Built React assetsincludes/- PHP classes and functionalityadmin/- WordPress admin assetspublic/- Public-facing assetsassets/- Root-level assets (fonts, images, etc.)magicchecklists.php- Main plugin filelicensing/- License management
Chunking Strategy
The build process creates optimized chunks:
- vendor.js: React, ReactDOM core libraries
- flowbite.js: Flowbite UI components
- utils.js: Utility libraries (drag & drop, tooltips, etc.)
- admin.js: Main admin application
- main.js: Public-facing application
Browser Support
The build targets ES2015+ browsers with:
- Modern JavaScript modules
- CSS Grid and Flexbox
- WebP images (with fallbacks)
Troubleshooting
Build Issues
- Ensure all dependencies are installed:
npm install - Clear dist directory:
rm -rf dist - Rebuild:
npm run build
Development Issues
- Make sure dev server is running:
npm run dev - Check for port conflicts (default: 3000)
- Verify WordPress debugging is enabled
Version Mismatch
Run npm run version-sync to automatically update plugin file version to match package.json.
Environment Detection
The plugin automatically detects the environment:
$this->is_dev_mode = $this->is_vite_dev_server_running();
This checks if the Vite dev server is accessible and switches between dev and production asset loading accordingly.
Build Output
The build process generates:
JavaScript Files
admin.js- Main admin React applicationmain.js- Public React applicationvendor-[hash].js- React & ReactDOMflowbite-[hash].js- Flowbite componentsutils-[hash].js- Utility libraries (DnD, react-select, etc.)
CSS Files
assets/index-[hash].css- Combined styles including Tailwind
Font Files
- Various
.woff2font files for Nunito Sans
How WordPress Loads the Scripts
The MCL_React_Dev class in includes/class-mcl-react-dev.php handles script loading:
- Development: Loads from
http://localhost:3000with ES modules - Production: Loads chunked files from
dist/with proper dependencies
Testing the Build
- Run
npm run buildto create production files - Visit
/wp-content/plugins/magicchecklists/test-build.phpto test standalone - Use WordPress admin to test integrated functionality
Troubleshooting
"Cannot use import statement outside a module"
- This was fixed by adding
type="module"to all script tags - Both development and production modes now properly load ES modules
CSS Warnings During Build
- Some complex CSS selectors may trigger warnings
- These are non-breaking and don't affect functionality
- Font files and assets are still copied correctly
Large Bundle Sizes
- Chunking strategy splits large dependencies into separate files
- WordPress loads dependencies in correct order
- Cache-friendly with hashed filenames
Architecture
Development:
Vite Dev Server โ React HMR โ WordPress Admin
Production:
Vite Build โ Chunked Assets โ WordPress Enqueue โ Browser
The system maintains full HMR functionality in development while providing optimized, production-ready builds for deployment.
What's inside
8 sections, 3 build commands, 2 environment modes, 1 chunking strategy, 1 architecture diagram
Change this for your project
- Replace
magicchecklistsin file names and paths with your plugin slug - Replace
MCL_React_Devclass name with your own PHP class - Replace
http://localhost:3000with your dev server URL if different - Replace
Nunito Sansfont references with your chosen font
Where it goes
Save in docs/ or the repository root. Gives agents and new contributors a map of the codebase.
Worth borrowing
- Auto-detecting dev mode by checking if the Vite dev server is reachable
- Version sync script that keeps package.json and PHP header in lockstep
- Chunking strategy that separates vendor, UI library, and app code
Related Documents
Design Document: BharatSeva AI
Describes a 10-agent AWS system that helps India's informal workers access government schemes via voice-first, serverless architecture.
OpenClaw Enterprise Transformation Plan
Transforms a single-user AI agent into a dual-mode platform supporting both viral open-source and Fortune 500 enterprise deployments through phased security, IAM, audit, multi-tenancy, and Kubernetes features.
University of Guelph Rocketry Club - Complete Tech Stack
Documents the full tech stack of a university rocketry club website with AI chatbot, member management, and project showcases.
Qwen Image and Edit: Open-sourcing and Local GGUF Generations with Lightning
Documents the Qwen-Image and Qwen-Image-Edit models, covering architecture, training, benchmarks, ComfyUI setup, and prompting techniques for local GGUF deployment.