Skip to content

Commit 6af855c

Browse files
authored
fix: remove assets/ from path to prevent build error when assets/ does not exist (#13)
BREAKING CHANGE: the generated template can now be found in `dist/env-config.template.js`. You may need to adjust your envsubst parameters
1 parent 71ab501 commit 6af855c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Instead of building your frontend on startup,
3535
you can use a config template like the one above and populate it using `envsubst`:
3636

3737
```Dockerfile
38-
CMD ["/bin/sh", "-c", "envsubst < ./dist/assets/env-config.template.js > ./dist/assets/env-config.js && exec nginx -g 'daemon off;'"]
38+
CMD ["/bin/sh", "-c", "envsubst < ./dist/env-config.template.js > ./dist/env-config.js && exec nginx -g 'daemon off;'"]
3939
```
4040

4141
`@geprog/vite-plugin-env-config` generates the required template from a list of variable names and provides the already populated file via the dev-server during development.

src/envConfig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function envConfig(userOptions: Partial<EnvConfigOptions> = {}): Plugin {
3838
const envConfigContent = createEnvConfigContent(userOptions.variables || [], false);
3939

4040
server.middlewares.use((req, res, next) => {
41-
if (req.url === '/assets/env-config.js') {
41+
if (req.url === '/env-config.js') {
4242
// standard headers
4343
res.setHeader('Content-Type', 'application/javascript; charset=utf-8');
4444
res.setHeader('Cache-Control', 'no-cache');
@@ -55,12 +55,12 @@ export function envConfig(userOptions: Partial<EnvConfigOptions> = {}): Plugin {
5555
closeBundle() {
5656
const templateContent = createEnvConfigContent(userOptions.variables || [], true);
5757

58-
const TEMPLATE_PATH = path.join(root, 'dist', 'assets', 'env-config.template.js');
58+
const TEMPLATE_PATH = path.join(root, 'dist', 'env-config.template.js');
5959
fs.writeFileSync(TEMPLATE_PATH, templateContent, 'utf8');
6060
},
6161

6262
transformIndexHtml(html) {
63-
return html.replace('</head>', '<script src="/assets/env-config.js"></script></head>');
63+
return html.replace('</head>', '<script src="/env-config.js"></script></head>');
6464
},
6565
};
6666
}

0 commit comments

Comments
 (0)