From 02b2eacfac1b46916e66ce77a763c698c4bcb117 Mon Sep 17 00:00:00 2001 From: eliot-akira Date: Wed, 11 Jan 2023 17:37:44 +0100 Subject: [PATCH] Fix cache busting for HTML files and wp.data --- esbuild.js | 2 +- src/wordpress-playground/wordpress/Dockerfile | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/esbuild.js b/esbuild.js index 4818086896..f5e332c519 100644 --- a/esbuild.js +++ b/esbuild.js @@ -252,7 +252,7 @@ function buildHTMLFile(filePath) { const outdir = globalOutDir; let content = fs.readFileSync(filePath).toString(); content = content.replace( - /(]+src=")([^"]+)("><\/script>)/, + /(]+src=")([^"]+)(" type="module"><\/script>)/, `$1$2?${CACHE_BUSTER}$3` ); const filename = filePath.split('/').pop(); diff --git a/src/wordpress-playground/wordpress/Dockerfile b/src/wordpress-playground/wordpress/Dockerfile index e0cc956995..8cf530ee16 100644 --- a/src/wordpress-playground/wordpress/Dockerfile +++ b/src/wordpress-playground/wordpress/Dockerfile @@ -156,13 +156,15 @@ RUN mv wordpress /wordpress && \ --no-node \ --preload /wordpress \ --js-output=/root/output/wp.js && \ - mv /root/output/wp.data /root/output/$OUT_FILENAME.data + if [ "$OUT_FILENAME" != "wp" ]; then \ + mv /root/output/wp.data /root/output/$OUT_FILENAME.data; \ + fi COPY ./build-assets/esm-prefix.js ./build-assets/esm-suffix.js /root/ # It's useful to add a "cache busting" query string to the .data file URL. # This tells web browsers it's a new file and they should reload it. -RUN export CACHE_BUSTER=$(md5sum /root/output/wp.data | awk '{print $1}'); \ +RUN export CACHE_BUSTER=$(md5sum /root/output/$OUT_FILENAME.data | awk '{print $1}'); \ cat /root/output/wp.js \ | sed "s#wp\.data#/$OUT_FILENAME.data?$CACHE_BUSTER#g" \ > /tmp/wp.js && \