This project is forked from the Craft CMS + Nuxt Starter and modified to be hosted on Netlify with static site generation (SSG) and prerendering.
This project expects you to deploy your site like this:
-
Craft CMS backend hosted on a server of your choice
-
Nuxt frontend hosted on Netlify, with three build environments:
staging,preview, andproductionENV=production: Uses SSG and prerendering to cache all page content statically on Netlify. Deploy withmasterbranch.ENV=preview: Uses Nuxt as a front-end SPA, reacts instantly to your changes in the Craft CMS backend. Used for the live preview feature. Deploy withmasterbranch.ENV=staging: Uses Nuxt as a front-end SPA, reacts instantly to your changes in the Craft CMS backend. Used as staging environment for development purposes. Should deploy withstagingoruatbranch.
To get started, clone this repository and following steps over at: https://github.com/craftcms/starter-nuxt?tab=readme-ov-file#quick-start
After you get everything done, move to here to deploy your site on Netlify.
graph TB
subgraph "Your Server"
CMS["Craft CMS Backend<br>api.yourdomain.com"]
end
subgraph "Netlify"
subgraph "Master Branch"
PROD["Production Environment<br>SSG + Prerendering<br>yourdomain.com"]
PREVIEW["Preview Environment<br>SPA<br>preview.yourdomain.com"]
end
subgraph "Staging/UAT Branch"
STAGING["Staging Environment<br>SPA<br>staging.yourdomain.com"]
end
end
CMS -->|"GraphQL API"| PROD
CMS -->|"GraphQL API"| PREVIEW
CMS -->|"GraphQL API"| STAGING
WEBHOOK["Netlify Build Hook<br>with JWS Verification"]
CMS -->|"Trigger rebuild on content update"| WEBHOOK
WEBHOOK -->|"Rebuild"| PROD
style CMS fill:#f9f,stroke:#333,stroke-width:2px
style PROD fill:#bfb,stroke:#333,stroke-width:2px
style PREVIEW fill:#bbf,stroke:#333,stroke-width:2px
style STAGING fill:#fbb,stroke:#333,stroke-width:2px
style WEBHOOK fill:#ff9,stroke:#333,stroke-width:2px
-
Update the
/frontend/queries/build.mjsfile to ensure it selects all Craft CMS entries' URIs you want to prerender. -
Update the
netlify.tomlfile with your site's address.- Replace
https://api.nuxt-starter.yourdomain.comwith your Craft CMS backend address. - Replace
https://nuxt-starter.netlify.appwith your SSG production address. - Replace
https://nuxt-starter-preview.netlify.appwith your SPA preview address. - Replace
https://nuxt-starter-staging.netlify.appwith your SPA staging address.
- Replace
-
You can put the entire project, backend and frontend into a single repository or separate them into two repositories. If you separate them, you will need to update the
netlify.tomlfile with the correct build command and publish directory.If you use a single repository, you can use the following
netlify.tomlfile:[build] base = "/frontend" command = "npm install && npm run generate" publish = "dist"
Otherwise, you should set the
baseto the root directory and update thecommandandpublishdirectory accordingly:[build] base = "/" command = "npm install && npm run generate" publish = "dist"
-
You can also add a Netlify build hook to your Craft CMS backend to trigger a rebuild of the frontend when you publish new content.
- Go to your Netlify site settings > Build & Deploy > Build hooks
- Create a new build hook and copy the URL
- Update your
./backend/.envfile to add the NETLIFY_BUILD_HOOK_URL and NETLIFY_BUILD_HOOK_JWS_SECRET values (see./backend/.env.examplefor reference) - The webhook functionality is already implemented in the Craft CMS module