Is it possible to use <static-site-env> without us...
# sst
d
Is it possible to use static-site-env without using ReactStaticSite, NextjsSite etc. I don’t want to use SST to deploy my app frontend, but populating the environment variables in the development environment is really handy. When deploying the frontend to production, I will manually manage the environment variables.
f
Yes, the way
sst-env
works is that it looks for SST’s
.build
directory in its parent folders. Parses an environmnt file in it and launches whatver command that comes after it with those environment variables.
So as long as you place ur frontend project inside the SST app. You can use
sst-env
.
d
My understanding was that the names of the environment variables themselves were defined in either the ReactStaticSite or NextjsSite constructs? If I have neither of those constructs in my stacks, how would SST know which environment variables to write to the
.build
directory?
To clarify, this is my NextjsSite construct, where the environment variables are defined. I want to remove this construct as I don’t want SST to try and build the app, deploy it to Cloudfront etc. However if I remove it, then SST will no longer know that it needs to write this environment variable names to the
.build
directory. It would be awesome to have a construct which all it does is define the environment variables.
My understanding is it would be a construct which only does this, without any of the other stuff re. cloudfront, s3, running the build command etc - https://github.com/serverless-stack/serverless-stack/blob/master/packages/resources/src/StaticSite.ts#L637-L653
f
Gotcha. One thing you could do: • run
sst start --outputs-file outputs.json
this will give you a JSON with all stack outputs • write a
sst-env
like bash script (a real simple script) that reads the
outputs.json
and set them as env vars • wrap the
next dev
command with the script
d
Ah cool, will give that a go. Thanks @Frank