windhamdavid 1 day ago
parent
commit
4c0470bd77
3 changed files with 22 additions and 1 deletions
  1. 1 0
      .gitignore
  2. 10 0
      functions.php
  3. 11 1
      webpack.config.js

+ 1 - 0
.gitignore

@@ -11,3 +11,4 @@ build/
 .vscode/
 
 _claude/scratch/
+.bs-reload

+ 10 - 0
functions.php

@@ -189,6 +189,16 @@ function dw_ask_widget() {
 }
 add_action( 'wp_footer', 'dw_ask_widget' );
 
+// Dev only: on a real post/page save (Gutenberg "Update"), touch a sentinel file that
+// BrowserSync watches, so the front-end preview reloads โ€” DB content changes aren't
+// visible to a filesystem watcher otherwise. Gated to WP_DEBUG โ†’ no-op in production.
+function dw_bs_reload_on_save( $post_id ) {
+	if ( ! ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) return;
+	if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) return;
+	@touch( get_template_directory() . '/.bs-reload' );
+}
+add_action( 'save_post', 'dw_bs_reload_on_save' );
+
 add_action('wp_footer', 'dw_analytics', 22);
 function dw_analytics() { ?>
 <script>

+ 11 - 1
webpack.config.js

@@ -79,7 +79,7 @@ module.exports = {
     }),
     new BrowserSyncPlugin({
       host: 'daw.stu',
-      port: 3030,
+      port: 81,
       proxy: 'https://daw.stu',
       https: {
         key: '/opt/homebrew/etc/httpd/ssl/daw.stu-key.pem',
@@ -93,12 +93,22 @@ module.exports = {
         './parts/**/*.html',
         './patterns/**/*.php',
         './theme.json',
+        './.bs-reload', // touched by save_post (functions.php) โ†’ reload after Gutenberg "Update"
       ],
       ignore: ['node_modules', 'build', 'js/v4-*', '*.min.*'],
       open: 'external',
       reloadDelay: 50,
       injectChanges: true,
       notify: false,
+      // Serve dev responses uncached so a reload always reflects the latest edit
+      // (no stale browser cache while iterating). Pairs with the `files` watch above,
+      // which already auto-reloads on .php / template / src changes.
+      middleware: function (req, res, next) {
+        res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0');
+        res.setHeader('Pragma', 'no-cache');
+        res.setHeader('Expires', '0');
+        next();
+      },
     }),
   ],
 };