-
Notifications
You must be signed in to change notification settings - Fork 21
/
inject-env.js
30 lines (24 loc) · 934 Bytes
/
inject-env.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const fs = require("fs");
const path = require("path");
const indexHtmlPath = path.join(__dirname, "index.html");
let indexHtmlContent = fs.readFileSync(indexHtmlPath, "utf8");
// Inject the environment variables
const envVars = {
VITE_CLICKHOUSE_URL: process.env.VITE_CLICKHOUSE_URL || "",
VITE_CLICKHOUSE_USER: process.env.VITE_CLICKHOUSE_USER || "",
VITE_CLICKHOUSE_PASS: process.env.VITE_CLICKHOUSE_PASS || "",
VITE_CLICKHOUSE_USE_ADVANCED: process.env.VITE_CLICKHOUSE_USE_ADVANCED || "",
VITE_CLICKHOUSE_CUSTOM_PATH: process.env.VITE_CLICKHOUSE_CUSTOM_PATH || "",
};
const scriptContent = `
<script>
window.env = ${JSON.stringify(envVars)};
</script>
`;
// Insert the script just before the closing </head> tag
indexHtmlContent = indexHtmlContent.replace(
"</head>",
`${scriptContent}</head>`
);
fs.writeFileSync(indexHtmlPath, indexHtmlContent);
console.log("Environment variables injected successfully");