From f2d7606abaec9d9472273d462918ce17a2c43fe7 Mon Sep 17 00:00:00 2001 From: fynks <75840152+fynks@users.noreply.github.com> Date: Fri, 24 Oct 2025 10:21:08 +0500 Subject: [PATCH] fix(replace-assets): correct asset paths and enhance JS preload tag handling --- scripts/replace-assets.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/replace-assets.js b/scripts/replace-assets.js index 0185bd9..7fb6e37 100644 --- a/scripts/replace-assets.js +++ b/scripts/replace-assets.js @@ -46,8 +46,8 @@ function replaceAssets() { }; const cssHash = safeHash(cssMinPath); const jsHash = safeHash(jsMinPath); - const cssTarget = cssHash ? `href="./css/styles-min.css?v=${cssHash}"` : 'href="./css/styles-min.css"'; - const jsTarget = jsHash ? `src="js/app-min.js?v=${jsHash}"` : 'src="js/app-min.js"'; + const cssTarget = cssHash ? `href="/css/styles-min.css?v=${cssHash}"` : 'href="/css/styles-min.css"'; + const jsTarget = jsHash ? `src="/js/app-min.js?v=${jsHash}"` : 'src="/js/app-min.js"'; // Replace CSS links in head - more flexible patterns const cssPatterns = [ @@ -72,6 +72,14 @@ function replaceAssets() { } } + // Update JS preload tags to include version hash + if (jsHash) { + const preloadMinJsPattern = /href=["']\/?js\/app-min\.js["']/g; + if (preloadMinJsPattern.test(updatedHeadContent)) { + updatedHeadContent = updatedHeadContent.replace(preloadMinJsPattern, `href="/js/app-min.js?v=${jsHash}"`); + } + } + // Replace JS script src in head - more flexible patterns const jsPatterns = [ /src=["']\.\/js\/app\.js["']/g,