feat: toggle HMR (BrowserSync) via ENABLE_HMR#719
Merged
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.
Mirror the plugin skeleton's AssetsHmrTest so the theme's HMR feature has the same coverage. Exercises the two private env-flag helpers in Assets via a fresh instance per case (each re-reads .env.local): - is_hmr_enabled(): defaults on when ENABLE_HMR is absent, off for 0/false/no/off (case-insensitive), on for 1/true/yes/on - is_browser_sync_disabled(): independent of HMR; off by default, on for truthy DISABLE_BS Backs up and restores any real .env.local so the developer's file is left untouched.
|
Rebased onto the updated #718 and added AssetsHmrTest (the https://github.com/rtCamp/features-plugin-skeleton/pull/707 had it; ours was missing). |
aryanjasala
commented
Jun 23, 2026
AnuragVasanwala
approved these changes
Jun 24, 2026
Mark the demo modules (media-text block extension, theme options, author bio), example components and page-creation pattern with grouped wp:example markers so init can drop selected sets while keeping the rest. The three Main.php modules use keyed markers to scope their shared regions.
AnuragVasanwala
pushed a commit
that referenced
this pull request
Jun 24, 2026
* feat: wire the Tailwind theme-token webpack plugin when present Gates GenerateTailwindThemePlugin (from @rtcamp/wp-tooling) on the entry file src/css/frontend/tailwind.css, guard-requiring wp-tooling so the build still works when it is absent. Dormant until the Tailwind feature creates the entry. * feat(scaffold): add Tailwind CSS opt-in feature Toggleable in manage mode: copies the entry CSS + PostCSS config and adds the tailwindcss / @tailwindcss/postcss devDeps; detected via the entry file. The build side lives in webpack.config.js. * docs(tailwind): fix stale default-enablement comments functions.php now defaults ELEMENTARY_THEME_ENABLE_TAILWIND to false (the scaffold feature flips it); the webpack token plugin is still entry-file gated at build time, and the wp-tooling catch only skips that plugin, not Tailwind compilation. * fix(tailwind): consume @rtcamp/tailwind-config and gate enqueue at runtime * feat: toggle HMR (BrowserSync) via ENABLE_HMR (#719) * feat(scaffold): add HMR enable/disable feature 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. * test(hmr): cover ENABLE_HMR master switch and DISABLE_BS override Mirror the plugin skeleton's AssetsHmrTest so the theme's HMR feature has the same coverage. Exercises the two private env-flag helpers in Assets via a fresh instance per case (each re-reads .env.local): - is_hmr_enabled(): defaults on when ENABLE_HMR is absent, off for 0/false/no/off (case-insensitive), on for 1/true/yes/on - is_browser_sync_disabled(): independent of HMR; off by default, on for truthy DISABLE_BS Backs up and restores any real .env.local so the developer's file is left untouched. * test(hmr): isolate env reads from the real .env.local * feat(scaffold): mark example sets for selective removal (#720) Mark the demo modules (media-text block extension, theme options, author bio), example components and page-creation pattern with grouped wp:example markers so init can drop selected sets while keeping the rest. The three Main.php modules use keyed markers to scope their shared regions. --------- Co-authored-by: Aditya Singh <adityasinghboss1234@gmail.com> --------- Co-authored-by: Aditya Singh <adityasinghboss1234@gmail.com>
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.