Giter Site home page Giter Site logo

andrewmclagan / react-env Goto Github PK

View Code? Open in Web Editor NEW
299.0 7.0 47.0 36.54 MB

Runtime environment variables for react apps.

License: MIT License

JavaScript 100.00%
create-react-app react docker environment-variables configuration kubernetes nextjs

react-env's Introduction

React Env - Runtime Environment Configuration

Build Status npm version Coverage Status

Populates your environment from .env files at run-time rather than build-time.

  • Isomorphic - Server and browser compatible.
  • Supports static site generation.
  • Supports multiple .env files.

README

Examples

Getting started

This package generates a __ENV.js file from multiple .env files that contains white-listed environment variables that have a REACT_APP_ prefix.

<script src="/public/__ENV.js" />

In the browser your variables will be available at window.__ENV.REACT_APP_FOO and on the server process.env.REACT_APP_FOO. We have included a helper function to make retrieving a value easier:

# .env
REACT_APP_NEXT="Next.js"
REACT_APP_CRA="Create React App"
REACT_APP_NOT_SECRET_CODE="1234"

becomes...

import env from "@beam-australia/react-env";

export default (props) => (
  <div>
    <small>
      Works in the browser: <b>{env("CRA")}</b>.
    </small>
    <small>
      Also works for server side rendering: <b>{env("NEXT")}</b>.
    </small>
    <form>
      <input type="hidden" defaultValue={env("NOT_SECRET_CODE")} />
    </form>
    <small>
      Entire safe environment:
      <pre>
        <code>{{JSON.stringify(env())}}</code>
      </pre>
    </small>
  </div>
);

.env file order of priority

We have implemented some sane defaults that have the following order of priority:

  1. {path-to-file} // from the --path, -p argument
  2. .env.{key} // from the --env, -e argument
  3. .env.local
  4. .env

Your config is available in the browser and process.env on the server. We suggest you add .env.local to .gitignore.

Common use cases

Environment specific config

Frameworks such as Next allow for some nice defaults such as .env.local, .env.production, .env. This has the limitation where you may want to run your app in different environments such as "staging, integration, qa" but still build a "production" app with NODE_ENV=production. With react-env this is possible:

# .env.staging
REACT_APP_API_HOST="api.staging.com"
# .env.production
REACT_APP_API_HOST="api.production.com"
# .env.qa
REACT_APP_API_HOST="api.qa.com"
# .env.integration
REACT_APP_API_HOST="api.integration.com"
# .env.local
REACT_APP_API_HOST="api.example.dev"
# .env
REACT_APP_API_HOST="localhost"

for staging you would simply set APP_ENV=staging where you run your app:

{
  ...
  "scripts": {
    "start": "react-env --env APP_ENV -- next start" // where .env.${APP_ENV}
  }
  ...
}

Thus REACT_APP_API_HOST=api.staging.com in your staging environment.

Please keep in mind that you have to pass the name of an environment variable to --env, not the value of it.

  • โœ” valid usage (macOS): APP_ENV=staging react-env --env APP_ENV -- next start
  • โŒ common mistake: react-env --env staging -- next start

Specifing an env file

You are also able to specify the path to a specific env file:

{
  ...
  "scripts": {
    "start": "react-env --path config/.env.defaults -- next start"
  }
  ...
}

You can use any combination of these two arguments along with the default .env, .env.local to build your runtime config.

Specifing an prefix for white-listed environment variables

You are also able to specify the prefix of white-listed environment variables:

{
  ...
  "scripts": {
    "start": "react-env --prefix NEXT_APP -- next start"
  }
  ...
}
# .env
NEXT_APP_NEXT="Next.js"
NEXT_APP_CRA="Create React App"
NEXT_APP_NOT_SECRET_CODE="1234"
Using prefix with jest

You need to add REACT_ENV_PREFIX env variable before jest command if you use env() during your tests:

{
  ...
  "scripts": {
    "test": "REACT_ENV_PREFIX=NEXT_APP jest --maxWorkers=3"
  }
  ...
}

Using with Docker entrypoint

It is possible to use this package as an ENTRYPOINT script inside a Dockerfile. This will generate your __ENV.js config file when the container boots and allow your package.json scripts to remain unchanged. Of course node binary must be present in your container.

FROM node:alpine

ENTRYPOINT yarn react-env --env APP_ENV

CMD yarn start

Arguments and parameters

$ react-env <args> -- <command>
  • <command>

You may pass a command, such as a nodejs entry file to the react-env cli tool. For example react-scripts, next dev, next start

  • --env, -e (default: null)

Specify the name of an existing environment variable, whose value is the name of an environment you want, to make react-env parse an environment specific env-file. For example, you may set APP_ENV=staging first and then apply --env APP_ENV flag. react-env would load .env.staging, .env.local, .env in that order with the latter taking priority.

  • --path, -p (default: null)

Specify a specific env file to load e.g. react-env --path .env.testing would load .env.testing, .env.local, .env in that order with the latter taking priority. a Combination of --env APP_ENV --path testing where APP_ENV=staging loads .env.testing, .env.staging, .env.local, .env as the priority order.

  • --dest, -d (default: ./public)

Change the default destination for generating the __ENV.js file.

  • --prefix (default: REACT_APP)

Change the default prefix for white-listed env variables. For exemple react-env --prefix CUSTOM_PREFIX will white-list variables like: CUSTOM_PREFIX_PUBLIC_KEY=my-public-key

  • --debug (default: false)

Enable debugging for react-env. This will log loaded browser environment variables into your console when running react-env --debug

3.x.x Breaking changes


As a significant breaking change we have dropped the ability to specify specific files via the --env argument. This argument now specifies environment file to be parsed depending on the running environment. For example --env APP_ENV or -e APP_ENV where APP_ENV=staging reads in .env.staging. It is very common for platforms to have staging, qa, integration environments that are still built in "production" mode with NODE_ENV=production. This allows for that usecase and many others.

-- You are still able to specify files via the --path, -p argument.


We have also dropped adding NODE_ENV by default as this was a security risk.


File is now named __ENV.js


Depandand command is now in the format react-env <args> -- <command>

react-env's People

Contributors

andrewmclagan avatar anthonycrowcroft avatar bb-in-hoodie avatar dependabot[bot] avatar headfox avatar ryantimesten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-env's Issues

how to pass env variables from docker compose

I have a docker compose file. I have to set the api url for the nextjs project

node_nextjs:
    image: "node16_build_custom"
    ports:
      - 3000:3000
    environment:
      - DS_PATH=/home/simha/app/torsha_datasets
      - REACT_APP_API_HOST=http://localhost:8000
    volumes:
      - type: bind
        source: ../CODE/nextjs_frontend
        target: /home/simha/app
    command:
      - sh
      - -c
      - |
        id
        yarn react-env
        pm2-runtime npm -- start
    stdin_open: true # Add this line into your service
    tty: true # Add this line into your service
    networks:
      - nginx_network

I am setting the REACT_APP_API_HOST=http://localhost:8000 in the docker compose

but yarn react-env does not create the env variable inside public/__ENV.js

I see

window.__ENV = {};

How to pass the docker compose env varialbe inside .env file

i tried

.env

REACT_APP_API_HOST=$REACT_APP_API_HOST

This does not work.

Dynamic PUBLIC_URL

I'm testing the waters for interest here. I worked up a solution for PUBLIC_URL, though I'm not sure if it's right for everyone. I'll discuss it, then see the sample Dockerfile at the end.

This solution has two special steps.

  1. First, before building, I set PUBLIC_URL to something I can find later, in my case {{base_url}}.
  2. Next, I add my own command to entrypoint.sh to find and replace that variable with the runtime environment.

This solution does have limitations, though solvable.

  1. Changing the value of $REACT_APP_BASE_URL across container restart has no effect, because the files are already written.
    • However, I could easily amend my sed command to create .bak files and there could be an attempt to restore any .bak files on boot, anticipating a potential need to find-and-replace again.
  2. My apps are pretty vanilla CRA apps, so I don't know if there are people using any fancy plugins for which this may not work.

If there's interest in making this part of react-env, I can whip up a pull request. I expect all the dev work would be isolated to the entrypoint.sh, and of course there'd be documentation updates.


#
# Stage 1
#
FROM node:12-alpine AS build

ENV PUBLIC_URL="{{base_url}}"

# Create app directory
WORKDIR /usr/src/app

# Bundle app source
COPY . .

# Install dependencies and build the app
RUN npm install --production && npm run build


#
# Stage 2
#
FROM beamaustralia/react-env:2.1.2

RUN sed -i "5ifind \/var\/www\/ -type f -exec sed -i'' -e 's|{{base_url}}|'\"\$REACT_APP_BASE_URL\"'|g' {} \\\;" /var/entrypoint.sh
RUN cat /var/entrypoint.sh

WORKDIR /var/www

# Copy app files from Stage 1
COPY --from=build /usr/src/app/build /var/www

In case it's not clear, my RUN command:

  1. is a sed command
  2. which inserts a find command into entrypoint.sh
  3. which runs a sed command on every file in /var/www
  4. which replaces {{base_url}} with the value of $REACT_APP_BASE_URL.

Fun right? ๐Ÿ˜€


BTW, I do not see this as a breaking change. It is fully opt-in. For my containers, the $REACT_APP_BASE_URL is commonly undefined in dev.

Incorrect type definitions for env function

This packages provides the following type definitions:

declare module "@beam-australia/react-env" { function env(key: string): string export = env }

The problem is that env function returns undefined if env variable is not present.

Also key parameter should be optional and in this case, function returns an object containing all available env variables

NextJS + Dockerfile

I'm unsuccessfully trying to get your library to work in Dockerfile.
My problem is as follows, I would like to pass APP_ENV as a build-arg to the Dockerfile and then make react-env generate the file according to the passed argument, having multiple .env (qa, dev, prod). Could you add an example to git with this?

I tried something like that:
CMD yarn react-env --path .env.${APP_ENV} && yarn start
where APP_ENV is a build-arg, but doesn't work.

NextJs build step

Since the idea of react-env is to "build once, run anywhere" how do I handle building a NextJs app upfront before knowing which environment the built app will run in? It cannot safely rely on defaults in .env file if for example I need to fetch environment-specific CMS content upfront. Am I misunderstanding the use case of react-env? Thanks and sorry this is not really an issue - I am just confused.

Docker Error: EACCES: permission denied, open '/app/public/__ENV.js

When running docker image I am getting an error while generating __ENV.js:

Error: EACCES: permission denied, open '/app/public/__ENV.js'

Screenshot 2021-12-10 at 17 01 26

Dockerfile:

FROM node:16-alpine AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json

USER nextjs

EXPOSE 3000

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry.
ENV NEXT_TELEMETRY_DISABLED 1

CMD ["yarn", "start"]

Possibly because I am not running docker on root user, which is recommended.

Limitations Azure Devops

@andrewmclagan I'm currently doing a spike into moving our company onto Azure Dev-ops and atm it currently can only do variable substitutions in JSON or XML would you be open some sort of way we could bind a JSON file instead of going direct to a JS file

CRA Docker example gone

Hi! I have noticed that with the release of v3.0.0, the example file for running a production Docker is gone as well as the Dockerfile that's probably used for the use-of-use nginx container is gone.

I think what would be good is if the README.md of the CRA example could be updated to add in an example on what to insert into a Dockerfile to make react-env work with a production container. This at least would make it not get obsolete fast but still give a good kick-start for people to make their own Dockerfile with the extra steps needed like apk add, etc.

window.__ENV undefined

Hi there,

I tried upgrading to latest package version and none of my envs were loading. I checked the source code and looks like it was changed from window._env to window.__ENV but when I check the global object window.__ENV is undefined but window._env still has all the envs stored there.

I have since downgraded but would like to upgrade once the above issue is resolved.

Usage with Jest and Storybook

Hi, I'm using react-env in a Next.js codebase and I had issues making it work in Jest tests and Storybook.

For Next.js, I'm using this script in the _app.tsx, using the next/script component:

<Script strategy="beforeInteractive" src="/__ENV.js" />

For both Jest and Storybook, I added the ENV=dev react-env -e ENV -- before the respective commands in the package.json (the same as for the next dev/next start), but I struggled with where to load the __ENV.js file.

In the end, I went for a simple import in both. In Jest's setupFilesAfterEnv (in my case test/config/setupFiles.ts):

import "../../public/__ENV"

The same for the Storybook's .storybook/preview.tsx:

import "../public/__ENV"

This seems to work for me, but my question is - is this the recommended approach?

Improvement ideas and caveats

I tried to assemble this together with a NextJS app and using Docker. I don't think I'll use this library, but I want to leave a couple comments on this since I've spent quite a lot of time understanding the whole process.

<script>

Here it is advised to import the __ENV.js script in the head like this:

<script src="/__ENV.js" />

Which is not optimal at all IMO. Just imagine that the page loads and then it makes a request back to the server to download the environment variables so it can retrieve the route of the api backend (for example).

The idea is that it should be inlined into the script. So the __ENV.js should be read inside the _document.jsx (and cached) and then set as HTML content.

It does not work with ASO

About Automatic Static Optimization, the following is said:

Note: In order to keep server-only secrets safe, Next.js replaces process.env.* with the correct values at build time.

Which means that in case you use process.env.* in your code that will be optimized out, it will still be done in build time. The file will be generated in a static directory and it will not matter what variable you pass into the environment when you call next start, it simply does not matter anymore.

The only reason the example works is becausegetInitialProps is overridden.

With that said, I don't understand why it is claimed that this library supports static site generation. I am kinda lost on this one.


Anyway, thanks for the library. It is really awesome that you published this in open source.

Using react-env on builded project

Hi,

I implemented this package because I want to deploy my react create app in multiple environments and I will have unique vars for each. eg:
env.local:
REACT_APP_API_URL=localhost:3000
env.staging:
REACT_APP_API_URL=api.staging.com
env.prod:
REACT_APP_API_URL=prod.staging.com

When i run APP_ENV=prod react-env --env APP_ENV -- react-scripts start it show the correct API_URL when logging env("API_URL") inside my running app when switching prod to staging etc. (logging window.__ENV gives undefined though, not sure why this is..)
So far so good.

Now in my deployments I want to use of react-scripts build instead of start. But how do I actually use it?
I don't find anything in the docs and I tried all kind of combos to try to get it working but I can't find the solution.

In the end I want everything in a Dockerfile, I was thinking something like this but it does not seem to work like this (I pass DEPLOY_ENV as a variable to the container) :

this is just one of the combos I tried:

RUN npm run build
ENTRYPOINT npx react-env --env DEPLOY_ENV --dest "build"
CMD serve -s -l 80 "./build"

the build folder is being served, ./build/__ENV.js is present but no env variables are available with env("API_URL")

I think it's a bit weird the docs only handle the dev start scripts but not the actual builds which is where the real need for dynamic environment variables comes into play, no?

I also tried several syntaxes out of docker but none seem to serve the env variables inside of my app

[Question] using react-env for S3 based deployments

as far as I understood, the result of using react-env is an nginx container built in with the correct env.js to be hosted in nginx

but, what if you wish to use different deployment environment?
my environment for an example, is S3 based, and deploying the nginx content to a bucket isn't necessarily the best idea.

I have thought of 2 possible solutions and I wanted to advise what is the best solution from your perspective:

  1. use the image as is and in the end, extract the www/var folder's content and sync only these files.
  2. making a PR (to this repo) to abstract the process from nginx and making the usage of nginx optional

p.s: I have to admit that I'm very impressed with what you've accomplished in a month (since initial commit) so kudos to you all ๐ŸŽ‰ ๐Ÿš€

window.__ENV not available

I see that __ENV.js is generated in public folder and it includes correct data. The problem is that when I go to browser console I don't see window.__ENV. Do I have to import that file somewhere?

Feedback/Docker Usage

Hey Andrew,

Thanks for this package. It's a nifty package!

I have some questions/feedback after seeing the readme. Could we get a simple setup process for projects? You have good documentation around the usage but setup is entirely missing? I have to kinda figure out which npm package it is tied to.

I know it's https://www.npmjs.com/package/@beam-australia/react-env and going to the github link via there redirects to this repo but would immensely help so that people will know especially since it's published under beam-australia and not your name.

yarn add @beam-australia/react-env

Could we also get the README.md published to the npm package for more visibility about the usage for people who come through there.

I came from the discussion from next.js about not embedding secrets into the docker container. Based on the current instructions in the README, isn't that what seems to be suggested? The only difference is that it's not directly in the compiled files.

With that being said, we're able to do this with your package by mounting the docker image with the following

docker run -p 8080:3000 -v $(pwd)/.env.staging:/app/.env.staging next-app

This way the secrets are truly generated at run time with your entrypoint script assuming:

APP_ENV=staging yarn react-env --env APP_ENV

Would you like me to open a PR with changes to the README?

Use with NextJS

Hi there. This is a great package. I have one problem though. I haven't been able to figure out how to include the __ENV.js file in the client.

What I've done is added it in the <Head> in _document.ts.

This one doesn't seem to work. From what I've read, Next requires files in public to be present at build time ๐Ÿ™„

....
<Head>
  <script type="text/javascript" src="public/__ENV.js></script>
</Head>
....

I tried this based on some other comments I saw with people having this problem with Next.

....
<Head>
  <script type="text/javascript" dangerouslySetInnerHTML={{__html: fs.readFileSync(path.join(process.cwd(), 'public/__ENV.js')}}></script>
</Head>
....

This works fine locally, but does not work when deployed in a Docker container. I've tried loads and loads of different approaches to getting the path to resolve correctly, but it always resolves to a directory for some task runner, which I assume Next is delegating to for rendering, so the file location is always wrong.

I just wanted to check and see if you had any run-ins with this sort of thing before I find a new path for handling env vars.

Thanks in advance!

[ HELP WANTED ] Usage with express.

Thanks for this awesome library. I had a question regarding its usage. I am trying to spin an express server.

const express = require('express');
const path = require('path');
const app = express();
const envfile = require('envfile');
const fs = require('fs');
var child_process = require('child_process');

var env = {
  REACT_APP_FYIPE_HOSTED: process.env.FYIPE_HOSTED,
  REACT_APP_HOST: process.env.HOST,
  REACT_APP_DASHBOARD_HOST: process.env.DASHBOARD_HOST,
  REACT_APP_BACKEND_HOST: process.env.BACKEND_HOST
}

fs.writeFileSync('.env', envfile.stringifySync(env));

child_process.execSync("react-env", {
  stdio: [0, 1, 2]
});

app.use(express.static(path.join(__dirname, 'build')));

app.get('/*', function (req, res) {
  res.sendFile(path.join(__dirname, 'build', 'index.html'));
});

app.listen(3003);

I am unable to access env var from code inside /src. I think the issue is with env() helper function.

[feature] Allow optional .env file path

Would be great to allow the an env file path to be passed as an argument, this would allow use-cases outside of the CRA defaults.

e.g.

react-env -e ../config/.env.development
# Or
react-env --env-file ../config/.env.development

How to pick specific .env file?

I've read the documentation and looked at the example CRA app but I can't figure out how to pinpoint a specific .env file.

I have a brand new CRA with the following file/folder structre

image

I then updated my package.json with the following...

  "scripts": {
    "start": "react-env --env staging -- react-scripts start"

I was expecting this to point to my .env.staging file when doing npm start but it doesn't. Instead it just loads the .env file.

I also tried react-env --env APP_ENV=staging -- react-scripts start but it didn't work either.

Where am I going wrong here?

This is the output from my npm start

$ npm start

> [email protected] start E:\Repos\ReactEnvTest\reactenvtest
> react-env --env staging

Writing runtime env  E:\Repos\ReactEnvTest\reactenvtest/public/__ENV.js
{
  "REACT_APP_CRA": "Create React App",
  "REACT_APP_NEXT": "Next.js",
  "REACT_APP_NOT_SECRET_CODE": "1234"
}

And this is the contents of my env.staging

REACT_APP_NEXT="Staging Next.js"
REACT_APP_CRA="Staging Create React App"
REACT_APP_NOT_SECRET_CODE="12345"

Type declarations

Hi is there currently a type declaration for this? looking to use this in our solution as a single build that can be deployed to an environment is 100% the best approach for us.

Can this be used to pass env vars to docker container for NGINX?

I have a react app and I want to run it in an NGINX container and also inject some configuration at runtime via environment variables. From what I can tell this is not possible because a nodejs runtime is required. Is that correct? If not, please point me to an example how I can run on NGINX and pass in env vars.

Possible improvement on Docker support

Currently the steps documented for Docker support do not quite match real world setup,

  • It's not quite common to use a Node image for production deployment.
  • yarn start clearly is using the debug build.

To support a commonly used base image such as nginx, which does not have Node installed, the challenge is how to generate __ENV.js on the fly without Node.

I attached a shell script below that works in a similar way,

#!/bin/sh

# react-env.sh

scriptname="./__ENV.js"
sourcename="$1"

if [ -z "$sourcename" ]; then
  current=$(eval "echo \"\$ENVIRONMENT\"")
  if [ -z "$current" ]; then
    sourcename=".env"
  else
    sourcename=".env.$current"
  fi
fi

# Recreate config file
rm -rf "$scriptname"
touch "$scriptname"

# Add assignment 
echo "window.__ENV = {" >> "$scriptname"

# Read each line in .env file
# Each line represents key=value pairs
while read -r line || [ -n "$line" ];
do
  if printf '%s\n' "$line" | grep -q -e '^#.*'; then
    continue
  fi

  [ -z "$line" ] && continue

  # Split env variables by character `=`
  if printf '%s\n' "$line" | grep -q -e '='; then
    varname=$(printf '%s\n' "$line" | sed -e 's/=.*//')
    varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//')
  fi

  # Read value of current variable if exists as Environment variable
  env=$(eval "echo \"\$$varname\"")
  value=$(printf '%s\n' "$env")
  # Otherwise use value from .env file
  [ -z "$value" ] && value=${varvalue}
  
  # Append configuration property to JS file
  echo "  $varname: \"$value\"," >> "$scriptname"
done < "$sourcename"

echo "}" >> "$scriptname"

It is written in POSIX sh syntax, as many base images don't have bash.

Documentation

I found the examples really helpful when using this for the implementation I was doing but the readme.md doesn't clearly point out the things I needed to do to get it running

[feature] Need tests

We need some test coverage for the function of env generation

Strategy

We only really need to do this in node as its the end user and is easy to test.

  1. Use jest
  2. mock the .env.development.local, .env.development, .env.local, .env files
  3. test that the package acts like the CRA docs describe environment precedence

Open for anyone... PR

[bug] Cannot run without a .env file present

Hi!,
Since there is no installation process, I just installed yarn add -dev @beam-australia/react-env and tried to run
react-env --env staging

Gotthe got the error

Writing runtime env  {PROJECT_PATH}/public/__ENV.js
{}
fs.js:114
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/Users/arthur/Projects/etv/fs/etview/public/__ENV.js'

EDIT: my .env.staging file on the root:
REACT_APP_GA="UA-XXXXX"

EDIT 2: By creating a .env file it works fine, but it is not reading my .env.staging file for some reason

Question

Does this work by overwriting the public/__ENV file at runtime?

Question: passing arguments to command

Hi, I see in the docs that I can do something like react-env <command with arguments> however I can't figure out the right syntax for this.

For example, I can't get the following to work, it doesn't pass --watch to jest:

react-env jest --watch

or any other command where I need to pas a --flag. What am I doing wrong?

Support envsubst to generate .env files from the actual environment

The envsubst tool is available in the container already, and can be leveraged to automatically generate the .env files from environment variables passed in to the Docker container at runtime. This in turn can make things really flexible for configuring the running app by simply changing the runtime environment without needing to change the files inside the container in any way.

Cache Busting

Hello this is more of a question on how/if you implement cache-busting. I am currently using react-env in a production application and we are often updating ENV vars. However, the file is cached for users and for us devs during testing. Just wondering if you ran into this as well.

Very useful library, really appreciate this work! ๐Ÿ‘

Broken Docker image on Docker Hub

I'm not sure if you're aware or not, but there is a Docker image on Docker Hub - https://hub.docker.com/r/beamaustralia/react-env - that runs a static website using react-env.

This was fantastic back when I first found it. However, it's now not been updated in 2 years and doesn't work with the current version of react-env. Which means that if you use the latest react-env in your project but try to use this docker image to deploy it then you'll likely waste hours trying to work out why things are broken.

I know it's not actually yourself that created this image, and I can't work out who did create it in order to message them, but it seemed worth mentioning if it can somehow stop other people having the same waste of time that I've just had!

Cheers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.