Conversation
There was a problem hiding this comment.
Pull request overview
Adds BrowserSync-based live reload (CSS injection + full-page reload) to the theme’s development workflow, integrating it into the existing webpack-based asset pipeline and conditionally loading the BrowserSync client in local/dev WordPress environments.
Changes:
- Add
browser-sync+browser-sync-webpack-pluginand wire BrowserSync into the webpack “scripts” config. - Add an
npm run devscript to run webpack in watch mode with the multi-config setup. - Conditionally enqueue the BrowserSync client script in PHP for
local/developmentenvironments.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| webpack.config.js | Adds BrowserSyncWebpackPlugin to enable reload/inject behavior during webpack watch builds. |
| package.json | Adds BrowserSync deps and a new dev watch script for the enhanced dev loop. |
| package-lock.json | Locks newly added BrowserSync-related dependencies. |
| inc/classes/class-assets.php | Enqueues the BrowserSync client on local/development to enable snippet-mode reloads. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const fs = require("fs"); | ||
| const path = require("path"); | ||
| const CssMinimizerPlugin = require("css-minimizer-webpack-plugin"); | ||
| const RemoveEmptyScriptsPlugin = require("webpack-remove-empty-scripts"); | ||
| const BrowserSyncPlugin = require("browser-sync-webpack-plugin"); | ||
|
|
||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| const [ scriptConfig, moduleConfig ] = require( '@wordpress/scripts/config/webpack.config' ); | ||
| const [ | ||
| scriptConfig, | ||
| moduleConfig, | ||
| ] = require("@wordpress/scripts/config/webpack.config"); |
There was a problem hiding this comment.
webpack.config.js was reformatted to use double quotes and tighter spacing, which conflicts with the repo’s established JS formatting (e.g., bin/init.js uses @wordpress/eslint/prettier style with single quotes and spaced parentheses). This is likely to cause lint/format failures; please run the formatter/prettier and keep the file consistent with the existing style (single quotes, spacing).
Description
Adds live reload and CSS hot-reloading to the dev workflow via BrowserSync. Running
npm run devnow watches for file changes. CSS updates inject in-place without a full reload; PHP, HTML, and JS changes trigger a full page reload.Technical Details
Implementation: BrowserSync snippet mode
instances on the same port).
http://localhost:3000. Requires define('WP_ENVIRONMENT_TYPE', 'local') in wp-config.php.
Known limitation: HTTPS local environments
Snippet mode fails silently on HTTPS local sites (LocalWP with SSL, VIP Dev Env). The browser blocks the WebSocket and HTTP connection from an HTTPS page to localhost:3000 as mixed content.
Workaround: BrowserSync proxy mode
In proxy mode, BrowserSync proxies the local WordPress site and serves it at https://[hostname]:3000. The SSL cert doesn't cover port 3000, so the browser shows a one-time "proceed anyway" warning — but HMR then works correctly with no mixed content errors. Proxy mode also auto-injects the client script, removing the need for the PHP enqueue. This is not implemented in this PR.
Checklist
To-do
Fixes/Covers issue
Fixes #643