@mittonface/static-site-env v0.35.1-next.2
@serverless-stack/static-site-env 
A simple CLI (@serverless-stack/static-site-env) that allows your static site to load the environment variables from your SST app. This means that you won't have to hard code the config from your backend.
Read more about how this works over on the ReactStaticSite doc.
View the @serverless-stack/static-site-env docs here.
Installation
Run the following in the root of your static site.
# With npm
$ npm install @serverless-stack/static-site-env --save-dev
# Or with Yarn
$ yarn add @serverless-stack/static-site-env --devUsage
Once installed, tweak the start command in your package.json scripts.
"scripts": {
"start": "sst-env -- react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},Now start your static site as usual.
$ npm run startNote that, you need to have sst start running for this to work.
How it works
Here's what's going on behind the scenes.
- The
sst startcommand generates a file with the values specified byReactStaticSite'senvironmentprop. - The
sst-envCLI will traverse up the directories to look for the root of your SST app. - It'll then find the file that's generated in step 1.
- It'll load these as environment variables before running the start command.
Note that, sst-env only works if the React app is located inside the SST app or inside one of its subdirectories.
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago