feat: toggle HMR (BrowserSync) via ENABLE_HMR#719
Draft
aryanjasala wants to merge 1 commit into
Draft
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a single master switch (ENABLE_HMR in .env.local) to control BrowserSync-based live reload across both the webpack build (server startup) and PHP (client script enqueue), making local development HMR easier to toggle per developer.
Changes:
- Introduces
ENABLE_HMRparsing inwebpack.config.jsand skips BrowserSync plugin setup when disabled. - Adds
ENABLE_HMRgating ininc/Core/Assets.phpso the BrowserSync client is only enqueued when the flag is enabled (while preservingDISABLE_BSas a client-only override). - Updates documentation and init scaffolding to expose/toggle the flag, and documents it in
.env.local.example.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| webpack.config.js | Reads ENABLE_HMR and disables BrowserSync plugin creation when HMR is toggled off. |
| inc/Core/Assets.php | Adds is_hmr_enabled() and gates BrowserSync client enqueue behind ENABLE_HMR. |
| docs/hmr.md | Documents the new ENABLE_HMR master switch and clarifies DISABLE_BS as client-only. |
| bin/scaffold.config.js | Adds an hmr feature toggle in npm run init to flip ENABLE_HMR in .env.local. |
| .env.local.example | Adds ENABLE_HMR with explanation and defaults for local setup. |
Comment on lines
142
to
145
| public function enqueue_browser_sync(): void { | ||
| if ( 'local' !== wp_get_environment_type() || $this->is_browser_sync_disabled() ) { | ||
| if ( 'local' !== wp_get_environment_type() || ! $this->is_hmr_enabled() || $this->is_browser_sync_disabled() ) { | ||
| return; | ||
| } |
HMR (BrowserSync live reload) is now a toggleable feature, gated on a single ENABLE_HMR flag in .env.local that both the build and PHP read: - webpack only starts the BrowserSync server when ENABLE_HMR is not off - Assets.php only enqueues the client under the same flag - the scaffold feature flips ENABLE_HMR in .env.local on enable/disable Default is on, so existing setups are unaffected. browser-sync deps stay installed (they are dev-only), so the toggle is a fast local switch. DISABLE_BS still works for the finer client-only case. Toggle from `npm run init` (manage mode) or by editing .env.local directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BrowserSync live reload behind one switch —
ENABLE_HMRin.env.local, read by both webpack and PHP. Default on, toggleable fromnpm run init.DISABLE_BSstays for the client-only case.