Skip to content

feat: toggle HMR (BrowserSync) via ENABLE_HMR#719

Draft
aryanjasala wants to merge 1 commit into
feat/tailwindfrom
feat/hmr
Draft

feat: toggle HMR (BrowserSync) via ENABLE_HMR#719
aryanjasala wants to merge 1 commit into
feat/tailwindfrom
feat/hmr

Conversation

@aryanjasala

Copy link
Copy Markdown
Member

BrowserSync live reload behind one switch — ENABLE_HMR in .env.local, read by both webpack and PHP. Default on, toggleable from npm run init. DISABLE_BS stays for the client-only case.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_HMR parsing in webpack.config.js and skips BrowserSync plugin setup when disabled.
  • Adds ENABLE_HMR gating in inc/Core/Assets.php so the BrowserSync client is only enqueued when the flag is enabled (while preserving DISABLE_BS as 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 thread inc/Core/Assets.php
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants