Fix base path handling in env script injection for index.html

master
Tudor Stanciu 2025-05-02 02:31:59 +03:00
parent 1a131a903b
commit 640ae564ff
1 changed files with 3 additions and 2 deletions

View File

@ -39,7 +39,8 @@ function updateIndexHtml(envFileName, basePath) {
// Replace any existing env script with the new one
const envScriptRegex = /<script src="[^"]*env(\.\w+)?\.js"[^>]*><\/script>/;
const newEnvScript = `<script src="${envFileName}"></script>`;
const scriptSrc = basePath ? `${basePath.endsWith("/") ? basePath : basePath + "/"}${envFileName}` : envFileName;
const newEnvScript = `<script src="${scriptSrc}"></script>`;
if (envScriptRegex.test(indexContent)) {
indexContent = indexContent.replace(envScriptRegex, newEnvScript);
@ -53,7 +54,7 @@ function updateIndexHtml(envFileName, basePath) {
}
fs.writeFileSync(indexPath, indexContent, "utf8");
console.log(`Updated ${indexPath} with base path: ${basePath || "/"} and env script: ${envFileName}`);
console.log(`Updated ${indexPath} with base path: ${basePath || "/"} and env script: ${scriptSrc}`);
}
function cleanupOldEnvFiles(newEnvFileName) {