Demo in use: https://nuxt-starter-kit.danbl.com/
This code HEAVILY borrows from two different repositories:
- Update of all libraries.
- Static site generation with payload
- Use of a vuex store
- Moving away from SASS and Bootstrap towards Tailwind and PostCSS
- Yarn as the command interface
First we are setting up a site that uses the base bootstrap demo version). But don't worry; we will add our own soon.
- Go to storyblok.com
- Choose Create new space
- Choose Play with a demo
- Wait for the demo to be created
- Get the preview key
Settings -> API Keys -> Preview Key
- Add a preview url
Settings -> General -> Preview Urls
- Add
http://localhost:3000
If you're reading this, then I'm guessing you know how to do this.
Otherwise, learn how to git or just use the zip
download.
Change the STORYBLOK_TOKEN
in the nuxt.config.js
, or set it using an environment variable.
// NOTE: The Storyblok token should NOT be commited to code as a general rule.
// Using an environment variable is a good choice
// e.g. const token = process.env.STORYBLOK_TOKEN
const STORYBLOK_TOKEN =
process.env.STORYBLOK_TOKEN || "fRhLxFwXxMQSuteNdL1Lrwtt";
Building for dev will let you see the site on your own computer! You will also be able to edit and change things through the storyblok interface.
# install dependencies
$ yarn install
# serve with hot reload at localhost:3000
$ yarn dev
The static production ready version of the site is able to be run locally.
# to build, export and then serve up the built files on http://localhost:3000
$ yarn static
# or to just build and export
$ yarn generate
# or to run each command individually
$ yarn build --static
$ yarn export
$ yarn serve
There are some issues in making the static version "non-static" in edit mode via Storyblok. These are being worked on where found.
This is the part where it all comes together.
- Start the site locally
http://localhost:3000
using either:yarn dev
- SPA (Single Page Application) in dev mode; auto updates on code changes.yarn static
- Serves statically generated HTML; emulates production.
- Go to storyblok.com
- Go to the demo space you have created.
Content -> Home
- Change the Preview url to the localhost option using the navigation dropdown
It should be working! If not, let me know and I'll try to help.
Deploying to Netlify is super easy. Set up a webhook to keep the generated files up to date with latest content.
- Create a site
- Connect your repo
- Set the build commands
- Build Command:
yarn generate
- Folder:
dist
- Build Command:
- Add the Storyblok PREVIEW key as an environment variable
Advanced -> STORYBLOK_TOKEN: XXXXXXXXXXXXXXXXXXX
- Don't use the public key unless you want it to be a non-editing site.
- Deploy Site and verify deployment
- Create a build webhook on Netlify
Build & Deploy -> Add build hook -> master
- Copy build webhook url to Storyblok
General -> Webhooks -> Story Published & Unpublished
If you want one site for both editing and delivery
yarn generate
- Use the preview key
Downsides to this is that your preview key is exposed. It may or may not be a concern to you.
- Delivery site
yarn generate
- Use the PUBLISHED key
- Editing site
yarn build --spa
yarn export
- Use the PREVIEW key
No static generation means everything is loaded dynamically, and should be up-to date. Another benefit is that the preview key is not exposed.
- Get it running using the instructions above
- Delete all the Storyblok pages from the demo site.
- Delete all components EXCEPT Global and Page:
- from Storyblok
- from the Components folder.
- from the
/plugins/components.js
- Modify Global and Page components to the data structure you need
- Global: Keep the header and footer sections
- Add pages
- Global of type Global
- Home of type Page
- Remove all custom styles from
assets/css/tailwind.css
If you leave this repo as a git secondary remote, you will be able to pull in changes when they are made here.
Tailwind usually purges all unused css classes within it's library on production build.
Dynamic classes must be whitelisted in the tailwind.config.js
for this project or they will be purged by PostCSS
https://github.com/FullHuman/purgecss-docs/blob/master/whitelisting.md