From e6138bd0e2ff5810fadb72660fb1b344c46258a8 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Wed, 12 Feb 2025 07:47:18 +0000 Subject: [PATCH] fix: improve electron asset path handling - Add extraResources config to package.json to properly include www directory - Update path rewriting in build-electron.js to handle all asset types - Fix modulepreload and stylesheet paths in index.html - Improve path handling in main.js for packaged app - Clean up file protocol handling and service worker management This fixes the issue with assets not loading in the packaged Electron app by ensuring all paths are correctly rewritten to reference the www directory in the app resources. --- scripts/build-electron.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/build-electron.js b/scripts/build-electron.js index 25c231f..5dd36ad 100644 --- a/scripts/build-electron.js +++ b/scripts/build-electron.js @@ -26,10 +26,21 @@ async function main() { // Fix paths in index.html const indexPath = path.join(wwwDir, 'index.html'); let indexContent = await fs.readFile(indexPath, 'utf8'); - indexContent = indexContent.replace(/src="\//g, 'src="./'); - indexContent = indexContent.replace(/href="\//g, 'href="./'); - indexContent = indexContent.replace(/\/assets\//g, './assets/'); // Fix asset paths with explicit relative path - indexContent = indexContent.replace(/\.\/\.\/assets\//g, './assets/'); // Clean up any double dots + indexContent = indexContent + // Fix absolute paths to be relative + .replace(/src="\//g, 'src="\./') + .replace(/href="\//g, 'href="\./') + // Fix relative asset paths + .replace(/src="\.\.\/assets\//g, 'src="./www/assets/') + .replace(/href="\.\.\/assets\//g, 'href="./www/assets/') + // Fix modulepreload paths specifically + .replace(/]*rel="modulepreload"[^>]*href="(?!\.?\/www\/)(\/\.\/)?assets\//g, ']*href="(?!\.?\/www\/)(\/)?assets\//g, ']*href="(?!\.?\/www\/)(\/\.\/)?assets\//g, ']*href="(?!\.?\/www\/)(\/)?assets\//g, '