thdxr
07/25/2021, 12:23 AMSNOWPACK_PUBLIC_
The ReactStaticSite rejects any env variabels not prefixed with REACT_APP
My question is why does this construct have to be specific to CRA or even React? Shouldn't StaticSite
also just support an environment
option that is passed to the build command?thdxr
07/25/2021, 12:50 AMreplaceValues: [
{
files: "**/*.js",
search: "import.meta.env.SNOWPACK_PUBLIC_API_URL",
replace: api.httpApi.apiEndpoint,
},
{
files: "**/*.js",
search: "import.meta.env.SNOWPACK_PUBLIC_USER_POOL_ID",
replace: user_pool.userPoolId,
},
{
files: "**/*.js",
search: "import.meta.env.SNOWPACK_PUBLIC_USER_POOL_CLIENT_ID",
replace: user_pool_client.userPoolClientId,
},
],
thdxr
07/25/2021, 12:50 AMFrank
environment
property is used in 3 places. For example, given this:
new ReactStaticSite(this, "ReactSite", {
path: "path/to/src",
environment: {
REACT_APP_API_URL: api.url,
},
});
1. environment
is used to generate build environment variables
REACT_APP_API_URL="{{ REACT_APP_API_URL }}" yarn run build
2. environment
is used to generate replaceValues
replaceValues: [
{
files: "**/*.js",
search: `{{ REACT_APP_API_URL }}`,
replace: api.url,
},
{
files: "index.html",
search: `{{ REACT_APP_API_URL }}`,
replace: api.url,
}
]
3. environment
is used to generate the .build/static-site-environment-output-keys.json
file, which will be consumed by sst-env
cliFrank
new ReactStaticSite(this, "ReactSite", {
path: "path/to/src",
buildCommands: `REACT_APP_API_URL="{{ REACT_APP_API_URL }}" yarn run build`
replaceValues: [
{
files: "**/*.js",
search: `{{ REACT_APP_API_URL }}`,
replace: api.url,
},
{
files: "index.html",
search: `{{ REACT_APP_API_URL }}`,
replace: api.url,
}
]
});
And you want the environment
property to pretty much just do this, correct?thdxr
07/25/2021, 12:36 PMthdxr
07/25/2021, 12:37 PMthdxr
07/26/2021, 4:58 PM_buildCommandEnvironment
with sst.StaticSite
and was able to get it to do what I needed. If that's made more official and then output to static-site-environment-output-keys.json
then my dreams all come truethdxr
07/27/2021, 12:46 AMFrank
SNOWPACK_PUBLIC_*
in html/js and then set the environment values at build time?thdxr
07/27/2021, 12:11 PM_buildCommandEnvironment: {
SNOWPACK_PUBLIC_API_URL: "{{ API_URL }}",
SNOWPACK_PUBLIC_USER_POOL_ID: "{{ USER_POOL_ID }}",
SNOWPACK_PUBLIC_USER_POOL_CLIENT_ID: "{{ USER_POOL_CLIENT_ID }}",
},
replaceValues: [
{
files: "**/*.js",
search: "{{ API_URL }}",
replace: api.httpApi.apiEndpoint,
},
{
files: "**/*.js",
search: "{{ USER_POOL_ID }}",
replace: user_pool.userPoolId,
},
{
files: "**/*.js",
search: "{{ USER_POOL_CLIENT_ID }}",
replace: user_pool_client.userPoolClientId,
},
],
Frank
SnowpackStaticSite
construct with sensible default for Snowpack. And ensure environments
starts with SNOWPACK_PUBLIC_
. What do you all think?thdxr
07/27/2021, 8:10 PMthdxr
07/27/2021, 8:11 PMStaticSite
Jay
thdxr
07/28/2021, 1:12 AMyarn start
which maps to snowpack dev
. Right now I'm using the last code snippet I sent to pass through environment variables to insert dummy values which then get replaced by the replacer. This works but I'd like to also be able to use sst-env
for local development. Ultimately I don't think this is specific to a build system or a frameworkJay
StaticSite
construct. @Frank says sst-env
should work as well.thdxr
07/28/2021, 2:34 AM