Skip to content

AWS via SST

SST (Serverless Stack) is an infrastructure-as-code framework for deploying to AWS. For static sites using SST’s StaticSite construct, pageflare integrates as part of the build command.

SST’s StaticSite construct runs a build command and deploys the output to S3 + CloudFront. Add pageflare to the build command so the optimized files are what gets deployed.

Terminal window
npm install -D @pageflare/cli

Update the build command in your sst.config.ts:

sst.config.ts
new StaticSite(stack, "Site", {
path: ".",
buildCommand: "npm run build && npx @pageflare/cli dist/ --in-place --no-progress",
buildOutput: "dist",
});

Or add pageflare to your package.json build script:

package.json
{
"scripts": {
"build": "astro build && npx @pageflare/cli dist/ --in-place --no-progress"
}
}

Set the environment variable in your .env file or pass it during deployment:

Terminal window
PAGEFLARE_LICENSE=your-license-key npx sst deploy

Or add it to the SST environment:

sst.config.ts
new StaticSite(stack, "Site", {
environment: {
PAGEFLARE_LICENSE: process.env.PAGEFLARE_LICENSE,
},
buildCommand: "npm run build && npx @pageflare/cli dist/ --in-place --no-progress",
buildOutput: "dist",
});

After deploying, check the SST CLI output for the pageflare summary:

Done 145.2 KB saved (38.1%) 1.2s
Files 42 total, 38 optimized, 4 unchanged, 0 errors
FrameworkOutput directorySST buildOutput
Astrodist/dist
Next.js static exportout/out
Hugopublic/public
Vitedist/dist

Build command not running Make sure the buildCommand is set in the StaticSite construct, not just in package.json. SST uses its own build command by default.

pageflare processes 0 files The path in the build command doesn’t match buildOutput. Both should point to the same directory.