Joshua Oransky
01/11/2022, 2:04 AMsst-env
to pull in dynamically generated values for my site, which works perfectly with sst start
(and running my static site in a local HTTP server). However, when I try to use sst deploy
, the static site tries to build and fails because it can't find the SST Outputs file (since it doesn't exist until the end of the stack deployment) and so the static site deploy fails. I'm kind of in a catch-22 situation, since I need to have those values in order to build & deploy my static site stack, but they don't exist yet until the stacks have all completed. Is there a way to tell SST to generate the env outputs file before running the StaticSite Stack so sst-env
can find it? Am I thinking about this wrong? Do I need to built my StaticSite first with sst start
running, then deploy without having the StaticSite construct run the build command?manitej
01/11/2022, 2:06 AMsst-env
in prod.Joshua Oransky
01/11/2022, 2:08 AMJoshua Oransky
01/11/2022, 2:10 AMbuildCommand: "npm run build",
which in my package.json runs:
"scripts": {
"build": "sst-env -- webpack"
},
So that I webpack can replace the env vars with the actual values generated.
Should I be doing this differently?manitej
01/11/2022, 2:11 AMJoshua Oransky
01/11/2022, 2:13 AMmanitej
01/11/2022, 2:15 AMconst { writeFile } = require('fs');
const targetPath = `./src/environments/environment.ts`;
const environmentFileContent = `
export const environment = {
production: ${false},
API_URL: "${process.env['DEV_API_URL']}",
};
`;
// write the content to the respective file
writeFile(targetPath, environmentFileContent, function (err: unknown) {
if (err) {
console.log(err);
}
console.log(`Wrote variables to ${targetPath}`);
});
manitej
01/11/2022, 2:15 AMJoshua Oransky
01/11/2022, 2:23 AMthdxr
01/11/2022, 2:26 AMthdxr
01/11/2022, 2:27 AMthdxr
01/11/2022, 2:28 AMsst-env
to webpack buildthdxr
01/11/2022, 2:28 AMsst-env
is purely for localJoshua Oransky
01/11/2022, 2:30 AMJoshua Oransky
01/11/2022, 2:31 AMsst deploy
and just not have the StaticSite construct run the build command... at that point it would simply copy whatever's in the dist
folder to S3... but that seems harder to automate later.thdxr
01/11/2022, 2:35 AMthdxr
01/11/2022, 2:35 AMsst-env
I think what you want will workJoshua Oransky
01/11/2022, 2:35 AMmanitej
01/11/2022, 2:39 AMJoshua Oransky
01/11/2022, 2:58 AMJon Holman
01/21/2022, 7:35 PMFrank
Jon Holman
02/01/2022, 4:58 AMJon Holman
02/01/2022, 5:03 AMFrank
Jon Holman
02/02/2022, 5:02 PMJon Holman
02/02/2022, 5:02 PMFrank
Jon Holman
02/02/2022, 8:59 PM