Closed Telokis closed 6 years ago
This sounds like something you'd want to do at build-time. Since you're using React, I assume you're also using Webpack, so you could use the DefinePlugin.
This app has some configuration that needs to be done and I'd like to do that after the app is minified/compressed.
I know I could do that at build time but I don't want to rebuild the whole app for that simple thing. The app itself will almost never change but this config part will change a lot between my clients.
http-server
is focused on static site hosting, so dynamically replacing text in any file is out of scope.
I agree with @SidneyNemzer that doing this at build time is best--if you want to stay satic. Otherwise, moving to Server Side Rendering (SSR), is a better solution.
I am currently working on a react front-end application that I'd like to embed in a docker container using
http-server
.This app has some configuration that needs to be done and I'd like to do that after the app is minified/compressed.
One solution I thought would be nice is to alter the files that
http-server
is sending. Using some pattern we could inject env variables into the app by simply saying something like so:This is an example of input that
http-serve
would intercept (if the variableMY_ENV_VAR
is available inprocess.env
) and inject in place of%MY_ENV_VAR%
.