A presentation at Vue.js Amsterdam in in Amsterdam, Netherlands by Debbie O'Brien
Full Static with Nuxt
Why Nuxt? Debbie O’Brien Frontend Tech Lead @Patterson Agency Contributor @webpack Writer @Ultimate Courses Teacher @Vue School Organiser @MallorcaJS, Vue Spain @Nuxt Team Member Debbie O’Brien @debs_obrien
Debbie O’Brien Why Nuxt?
Nuxt Benefits What Jake said debs_obrien
debs_obrien
debs_obrien
Gridsome or Nuxt? Whatever just go Static debs_obrien
Why Static? No server: cheaper, safer Better offline support Better performance Reduces Carbon footprint debs_obrien
debs_obrien
debs_obrien
debs_obrien
debs_obrien
debs_obrien
But Static is very Static Or is it? debs_obrien
debs_obrien
debs_obrien
debs_obrien
Is static really static? debs_obrien
API’s Forms CMS Auth e-commerce debs_obrien
Headless CMS Contentful CraftCMS Storyblok Sanity Wordpress debs_obrien
Netlify CMS photo of cms debs_obrien
Netlify CMS photo of cms debs_obrien
Netlify CMS debs_obrien
index.html <!DOCTYPE html> <html> <head> <meta charset=”utf-8” /> <meta name=”viewport” content=”width=device-width, initial-scale=1.0” /> <title>Content Manager</title> <script src=”https://identity.netlify.com/v1/netlify-identity-widget.js”></script> </head> <body> <!— Include the script that builds the page and powers Netlify CMS —> <script src=”https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js”></script> </body> </html> debs_obrien
config.yml collections: - name: ‘blog’ label: ‘Blog’ format: ‘json’ folder: ‘assets/content/blog’ create: true slug: ‘{{slug}}’ fields: - { label: ‘Title’, name: ‘title’, widget: ‘string’ } - { label: ‘Publish Date’, name: ‘date’, widget: ‘datetime’ } - { label: ‘Body’, name: ‘body’, widget: ‘markdown’ } debs_obrien
blog debs_obrien
index.vue debs_obrien
_blog.vue debs_obrien
Nuxt Dynamic Routes generate: { routes() { return fs.readdirSync(‘./assets/content/blog’) .map((file) => { return { route: /blog/${path.parse(file).name}
, payload: require(./assets/content/blog/${file}
),
debs_obrien
Nuxt Crawler generate: { routes() { return fs.readdirSync(‘./assets/content/blog’) .map((file) => { return { route: /blog/${path.parse(file).name}
, payload: require(./assets/content/blog/${file}
),
debs_obrien
Nuxt Crawler <div v-for=”post in blogPosts”> <nuxt-link :to=“/blog/${post.slug}
“> {{ post.title }} </nuxt-link> </div>
debs_obrien
Nuxt Crawler debs_obrien
Not just for blogs debs_obrien
Data debs_obrien
debs_obrien
Hasura show web of hasura debs_obrien
Add a new table show hasura table debs_obrien
Browse, Modify, Delete show hasura table debs_obrien
GraphQL Endpoint show the endpoint debs_obrien
GraphQL Playground debs_obrien
Call the GraphQL API modules: [ ‘@nuxtjs/apollo’, ], debs_obrien
Apollo import { HttpLink } from … import { InMemoryCache } from … const GRAPHCMS_API = ‘https://yourEndpoint’ export default () => ({ link: new HttpLink({ uri: GRAPHCMS_API }), … }) debs_obrien
Add our Query import gql from ‘graphql-tag’ export const workshops = gql` query workshops { workshops(order_by: { date: desc }) { title topic date … debs_obrien
Apollo apollo: { $loadingKey: ‘loading’, workshops: { query: workshops, }, }, debs_obrien
Network Tab - Call API debs_obrien
Generate on Update debs_obrien
Create your trigger debs_obrien
Netlify Build Hooks Generate on Update debs_obrien
Add the URL to Hasura debs_obrien
Netlify Deploys image of deploy debs_obrien
Nuxt Hydration Static Site becomes dynamic debs_obrien
debs_obrien
debs_obrien
debs_obrien
debs_obrien
Nuxt Static Module Call the API on page change Call the payload on page change debs_obrien
Call the payload debs_obrien
Nuxt Static Module Instead of Apollo smart queries use AsyncData until target static is released debs_obrien
Async Data async asyncData({ app, route, error }) { try { const client = app.apolloProvider.defaultClient const response = await client.query({ query: conferencesQuery, }) return { conferences: response.data.conferences, … debs_obrien
Nuxt Static Module You don’t have to expose your API to the public Decide when to publish new content from your API by re-generating your website Fully static is much faster API calls have latency - always takes longer Payload files are cached and offline support with PWA module debs_obrien
Convert to a static site mode: ‘universal’, nuxt generate debs_obrien
Convert to a static site debs_obrien
SPA inside a Static site generate: { fallback: true, exclude: [/booking/] } debs_obrien
Why Static Sites debs_obrien
debs_obrien
Why Static? No server: cheaper, safer Better offline support Better performance Reduces Carbon footprint debs_obrien
Think Static debs_obrien
debs_obrien
Thank you Debbie O’Brien Frontend Tech Lead Consultant Open Source Contributor https://github.com/debs-obrien/nuxt-boilerplate-project debs_obrien
Static sites have many benefits from costs to performance and even reducing the carbon footprint. And with the new static module from Nuxt static is going to a whole new level. Static sites are the future and they can used for more than just blogs.
Here’s what was said about this presentation on Twitter.
🙌🏻 The amazing @debs_obrien explains the new static target soon available in @nuxt_js at @vuejsamsterdam 2020. pic.twitter.com/M115Cj6GXr
— Alexandre Chopin (@IamNuxt) February 21, 2020
And closing off #VuejsAmsterdam 2020 @debs_obrien talking how to go full static with nuxt!
— Ramona (@CodesOfRa) February 21, 2020
Also as for today she is @nuxt_js team member!
Congratulations Debbie! pic.twitter.com/oaY8fr3Q1Q
@debs_obrien talks about getting full static with #Nuxtjs and how she got an @HasuraHQ project up and running within 2-3 hours without having any experience with #graphql. #VueJsAmsterdam
— Vanessa Böhner (@vannsl) February 21, 2020
If you wanna find out more about Hasura, ask @rubydwarf 👋 pic.twitter.com/VtJeoChl4G
The wonderful @debs_obrien is closing #VuejsAmsterdam with some beautiful references, great content and a serious message about the impact of our work on climate change. Thank you! pic.twitter.com/28T4vGIukJ
— Roman Kuba (@Codebryo) February 21, 2020
Static isn't really static even though it has the connotation of being so. @debs_obrien closes us off with a talk about static sites and harnessing @nuxt_js and @NetlifyCMS to create static yet dynamic sites #VuejsAmsterdam pic.twitter.com/ypdaewgpnM
— Divya 📍@vuejsAmsterdam (@shortdiv) February 21, 2020
Amazing talk about Full Static websites with Nuxt and even a better dance at the end.
— Edu (@edufarre) February 21, 2020
~ Think static@debs_obrien @vuejsamsterdam pic.twitter.com/L3byXtK1pZ
Very interesting talk by @debs_obrien closing the @vuejsamsterdam conference pic.twitter.com/Elk5dKMI17
— Nikola Kumric @VuejsAmsterdam (@nkumric) February 21, 2020