Fix base path handling in env script injection for index.html
parent
1a131a903b
commit
640ae564ff
|
@ -39,7 +39,8 @@ function updateIndexHtml(envFileName, basePath) {
|
||||||
|
|
||||||
// Replace any existing env script with the new one
|
// Replace any existing env script with the new one
|
||||||
const envScriptRegex = /<script src="[^"]*env(\.\w+)?\.js"[^>]*><\/script>/;
|
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)) {
|
if (envScriptRegex.test(indexContent)) {
|
||||||
indexContent = indexContent.replace(envScriptRegex, newEnvScript);
|
indexContent = indexContent.replace(envScriptRegex, newEnvScript);
|
||||||
|
@ -53,7 +54,7 @@ function updateIndexHtml(envFileName, basePath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(indexPath, indexContent, "utf8");
|
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) {
|
function cleanupOldEnvFiles(newEnvFileName) {
|
||||||
|
|
Loading…
Reference in New Issue