This project requires Node.js and Yarn to be installed. To get started:
# create env file, and set the variables
cp .env.example .env
# install dependencies
yarn
Ask a team member how to obtain the required env variables.
See available scripts (like yarn dev
) below.
The site is created as lightweight isomorphic website connected to a headless CMS, so that it can grow from a landing page to a full-fledged site including a geo app. The setup includes:
vue-datocms
provides handy Vue components and utilties for DatoCMS data.This package uses Nuxt's default directory structure. A component's file (*.vue
) and optional data structure (*.fragment.graphql
) are bundled in a directory with the name of the component. Pages typically also have an adjoining *.query.graphql
file for data loading.
src/
assets/icons/
components/
Example/
index.js
Example.vue
Example.fragment.graphql
pages/
_param/
index.vue
index.query.graphql
static/
fonts/
images/
The Nuxt app is connected to the CMS via the DatoCMS GraphQL API. To make data loading simple, this project uses graphql-loader
, a custom $datocms
plugin for data fetching and live previews. Together these enable us to put *.query.graphql
files next to our page templates (*.vue
), load them directly and use the helper to fetch the data:
<template>
<div>
<h1>{{ page.title }}</h1>
<DatocmsImage :data="page.image.responsiveImage" />
</div>
</template>
<script>
import query from './index.query.graphql'
export default {
async asyncData ({ $datocms, $preview }) {
const { page } = await $datocms.fetchData({ query, preview: !!$preview })
return { page }
},
head () {
return this.$datocms.toHead(this.page.seo)
},
mounted () {
if (this.$nuxt.isPreview) {
this.$datocms.subscribeToData({
query,
onData: ({ page }) => { this.page = page },
})
}
},
}
</script>
Where a simple index.query.graphql
could look like:
#import '../components/ResponsiveImage/ResponsiveImage.fragment.graphql'
query ExampleQuery($locale: SiteLocale) {
page: examplePage(locale: $locale) {
title
seo: _seoMetaTags { attributes, content, tag }
image {
responsiveImage(
imgixParams: { fit: crop, w: 300, h: 300, auto: format }
) {
...responsiveImageFragment
}
}
}
}
$datocms.request
and use them in the query..graphql
files with the VSCode GraphQL ExtensionFinally you can view unpublished content by enabling preview mode. Navigate to /?preview=true&secret={PREVIEW_MODE_SECRET}
or follow preview links from the CMS to enable it.
yarn ... |
task |
---|---|
dev |
starts development server on localhost:4999 (is "GWWW" in "T9") |
dev:netlify |
starts development server in Netlify setup on localhost:4999 , more realistic, less DX, helpful for testing (edge) functions |
analyze |
analyzes and visualizes output bundles |
build |
creates optimised production build |
start |
starts local server to test production build |
Follow these steps in order to release a new version to production:
development
into main
main
as the target