Skip to content

AWS Amplify

AWS Amplify Hosting provides a fully managed CI/CD pipeline for static and server-rendered apps. pageflare slots in as a post-build step in your amplify.yml build configuration.

Amplify runs a configurable build pipeline defined in amplify.yml. Add pageflare as a post-build command that optimizes the output before Amplify deploys it.

  1. Go to your app in the Amplify console.
  2. Navigate to Hosting > Environment variables.
  3. Add a variable named PAGEFLARE_LICENSE with your license key.
  4. Save.

Add pageflare installation and optimization to your build spec:

amplify.yml
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
postBuild:
commands:
- curl -fsSL https://get.appz.dev/pageflare/install.sh | sh
- ~/.pageflare/bin/pageflare dist/ --in-place --no-progress
artifacts:
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- node_modules/**/*
- .pageflare/**/*

Replace dist/ with your framework’s output directory.

If you prefer installing via npm:

amplify.yml
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
postBuild:
commands:
- npx pageflare dist/ --in-place --no-progress
artifacts:
baseDirectory: dist
files:
- '**/*'

This requires @pageflare/cli as a dev dependency in your package.json.

Add .pageflare/**/* to the cache.paths in amplify.yml to avoid re-downloading the binary on every build:

cache:
paths:
- node_modules/**/*
- .pageflare/**/*
amplify.yml
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
postBuild:
commands:
- npx pageflare dist/ --in-place --no-progress
artifacts:
baseDirectory: dist
files:
- '**/*'
amplify.yml
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
postBuild:
commands:
- npx pageflare out/ --in-place --no-progress
artifacts:
baseDirectory: out
files:
- '**/*'
amplify.yml
version: 1
frontend:
phases:
build:
commands:
- hugo
postBuild:
commands:
- curl -fsSL https://get.appz.dev/pageflare/install.sh | sh
- ~/.pageflare/bin/pageflare public/ --in-place --no-progress
artifacts:
baseDirectory: public
files:
- '**/*'
VariableDescription
PAGEFLARE_LICENSEPro license key. Set in Amplify console.

After deploying, check the Build logs in the Amplify console. Expand the postBuild phase and look for the pageflare summary:

Done 145.2 KB saved (38.1%) 1.2s
Files 42 total, 38 optimized, 4 unchanged, 0 errors

pageflare command not found Make sure the install command runs before the optimize command in postBuild. If using npm, ensure @pageflare/cli is in devDependencies and npm ci ran in preBuild.

Binary not cached between builds Add .pageflare/**/* to cache.paths. Amplify caches these paths between builds so the binary doesn’t need to be downloaded every time.

Build timeout Amplify has a default build timeout of 30 minutes. For very large sites, pageflare optimization should complete well within this limit. If builds are slow, run with --log info to identify the bottleneck.