Skip to content

Commit

Permalink
fix: remove assets/ from path to prevent build error when assets/ doe…
Browse files Browse the repository at this point in the history
…s 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
  • Loading branch information
lukashass committed Jan 31, 2022
1 parent 71ab501 commit 6af855c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Instead of building your frontend on startup,
you can use a config template like the one above and populate it using `envsubst`:

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

`@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.
6 changes: 3 additions & 3 deletions src/envConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function envConfig(userOptions: Partial<EnvConfigOptions> = {}): Plugin {
const envConfigContent = createEnvConfigContent(userOptions.variables || [], false);

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

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

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

0 comments on commit 6af855c

Please sign in to comment.