-
Notifications
You must be signed in to change notification settings - Fork 9
HMR / Live Reload Evaluation & Implementation #643
Copy link
Copy link
Open
Description
Overview
The current development workflow requires a full page reload to see CSS or JS changes. This task evaluates whether Vite can be integrated into the theme-elementary build pipeline to provide Hot Module Replacement (HMR) for CSS/JS, or at minimum a fast whole-page reload on PHP/HTML changes.
This is a dual-track task: evaluation first, then implementation if feasible.
Objective
Evaluate and implement at least one of the following:
- CSS/JS HMR via Vite — changes to SCSS/JS files reflect in the browser without a full reload
- Full-page reload on PHP/HTML changes — Vite watches PHP template files and triggers a browser reload when they change
If successful, document the approach and assess whether it can be extended to features-plugin-skeleton as well
Evaluation Criteria
Before committing to an implementation, answer the following questions:
| Question | Notes |
|---|---|
| Can Vite act as a dev server alongside a local WordPress instance? | Might need proxy/middleware config |
| Does HMR conflict with Gutenberg's editor iframe? | HMR in editor context is complex |
What is the impact on the existing webpack.config.js? |
- |
| Can the Vite setup be scoped to non-block assets only? | CSS/JS outside Gutenberg is simpler |
Implementation Approach (if feasible)
Option A — Vite for Theme Assets (CSS/JS HMR)
- Add
viteas a dev dependency - Configure
vite.config.js - Map theme entry points (
assets/src/css/,assets/src/js/) to Vite - Use Vite's HMR for SCSS and JS modules
- Keep
@wordpress/scriptsfor Gutenberg block assets (blocks run in the editor iframe)
Option B — BrowserSync / Full-Page Reload Fallback
- If Vite HMR proves too complex w/ Gutenberg, implement BrowserSync via the
webpack.config.jsdevServer? - Watches PHP, TWIG, CSS, JS files and triggers a browser reload
- Lower DX gain than true HMR but zero risk to block editor compatibility
Steps
- Spike: Set up a throwaway branch; attempt Vite integration against a local WordPress instance. Document what works and what breaks.
- Decision: Based on the spike, choose Option A or Option B (or a hybrid). Document the decision.
- Implementation: Implement the chosen approach in
theme-elementary. Updatepackage.jsonscripts (npm run devshould start the HMR/reload server). - Verify: Confirm that making a SCSS change reflects in the browser within 1–2 seconds without a manual reload.
- Document: Write setup instructions in
docs/hmr.mdcovering how to start the dev server alongside local WP instance.
Acceptance Criteria
- Evaluation spike completed and findings documented (even if implementation is not feasible)
- At minimum one of the following is working: CSS HMR, JS HMR, or full-page reload on file change
-
npm run devstarts the enhanced dev server;npm run buildstill produces production assets correctly - No regressions in block editor functionality
- Developer setup documented in the repo
- Feasibility for
features-plugin-skeletonassessed and documented
Notes
- If neither option is feasible within the time budget, close the task with a documented "not feasible at this time" finding. This is an acceptable outcome — do not over-engineer.
- Consider testing against the Gutenberg editor specifically — HMR inside the editor iframe has known compatibility issues.
Reactions are currently unavailable