You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.7 KiB
61 lines
1.7 KiB
/**
|
|
* Fix path resolution issues in the Electron build
|
|
*/
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const glob = require('glob');
|
|
|
|
// Fix asset paths in HTML file
|
|
function fixHtmlPaths() {
|
|
const htmlFile = path.join(__dirname, '../dist-electron/index.html');
|
|
if (fs.existsSync(htmlFile)) {
|
|
let html = fs.readFileSync(htmlFile, 'utf8');
|
|
|
|
// Convert absolute paths to relative
|
|
html = html.replace(/src="\//g, 'src="./');
|
|
html = html.replace(/href="\//g, 'href="./');
|
|
|
|
fs.writeFileSync(htmlFile, html);
|
|
console.log('✅ Fixed paths in index.html');
|
|
}
|
|
}
|
|
|
|
// Fix asset imports in JS files
|
|
function fixJsPaths() {
|
|
const jsFiles = glob.sync('dist-electron/assets/*.js');
|
|
|
|
jsFiles.forEach(file => {
|
|
let content = fs.readFileSync(file, 'utf8');
|
|
|
|
// Replace absolute imports with relative ones
|
|
const originalContent = content;
|
|
content = content.replace(/["']\/assets\//g, '"./assets/');
|
|
|
|
if (content !== originalContent) {
|
|
fs.writeFileSync(file, content);
|
|
console.log(`✅ Fixed paths in ${path.basename(file)}`);
|
|
}
|
|
});
|
|
}
|
|
|
|
// Add base href to HTML
|
|
function addBaseHref() {
|
|
const htmlFile = path.join(__dirname, '../dist-electron/index.html');
|
|
if (fs.existsSync(htmlFile)) {
|
|
let html = fs.readFileSync(htmlFile, 'utf8');
|
|
|
|
// Add base href if not present
|
|
if (!html.includes('<base href=')) {
|
|
html = html.replace('</head>', '<base href="./">\n</head>');
|
|
fs.writeFileSync(htmlFile, html);
|
|
console.log('✅ Added base href to index.html');
|
|
}
|
|
}
|
|
}
|
|
|
|
// Run all fixes
|
|
fixHtmlPaths();
|
|
fixJsPaths();
|
|
addBaseHref();
|
|
|
|
console.log('🎉 Electron path fixes completed');
|