vueschool.io

🤞

Deployments 🚀

@vueschool_io

Netlify

Connect Git repository
GitHub • GitLab • BitBucket

@vueschool_io

Netlify

Configuration

@vueschool_io

Profit 🎉

💧

💧

💧

💧

💧

💧

💧

💧

💧

💧

💧

💧

💧

💧

@vueschool_io

No Nuxt/Netlify?

@vueschool_io

SEO & meta tags 🧚‍♀️

@vueschool_io

Meta tags are defined in component's head

// pages/contact.vue
<template>...</template>

<script>
export default {
  head() {
    return {
      title: "Contact Us",
      meta: [
        { name: "twitter:title", content: "Contact us - if you want" },
        { name: "twitter:description", content: "Say something funny or bust us with questions, it's up to you." },
        { name: "twitter:card", content: "summary_large_image" },
        { name: "twitter:image", content: "https://i.imgur.com/XllovKU.png" }
      ]
    }
  }}
</script>

@vueschool_io

Twitter Card

@vueschool_io

Dynamic Content?

@vueschool_io

Blog

/posts/{id}
  • Generate a static file for each post
  • Fetch data from API for each file
  • Set meta information dynamically

@vueschool_io

asyncData ⚡️

@vueschool_io

asyncData

asyncData runs before loading the page component 
// ExamplePage.vue

export default {
  data () {
    return { username: 'hootlex' }
  },
  async asyncData ({$axios}) {
    let posts = await $axios.$get('posts')
    return {posts}
  },
}

@vueschool_io

@vueschool_io

Dynamic Routes

@vueschool_io

Dynamic Routes in Nuxt

/posts/{id}

@vueschool_io

_id.vue

// pages/posts/_id.vue
<template>....</template>

<script>
  export default {
    head () {
      return {
        title: this.post.title,
        meta: [
          { name: 'twitter:title', content: this.post.title},
          { name: 'twitter:description', content: this.post.body}
        ]
      }
    },
    data () {
      return {
        // whatever
      }
    },
    async asyncData ({params, $axios, payload}) {
      let post = await $axios.$get(`posts/${params.id}`)
      return {post}
    }
  }
</script>

@vueschool_io

By default Nuxt will not generate static pages for dynamic routes.

@vueschool_io

The generate property

// nuxt.config.js

generate: {
    routes: [
      '/posts/1',
      '/posts/2',
      '/posts/3'
    ]
}

@vueschool_io

The generate property

Define routes as a function.
// nuxt.config.js

generate: {
  async routes () {
    let response = await axios.get('/api/posts')
    return response.data
      .map(post => ({`posts/${post.id}`}))
  }
},

@vueschool_io

Let's Generate 🏭

@vueschool_io

@vueschool_io

Static Output

@vueschool_io

Static File

@vueschool_io

@vueschool_io

Bonus 🌟

@vueschool_io

Cross Platform Applications

image from vensi.com

@vueschool_io

Offline Blog?

@vueschool_io

When SSG might not be a good fit

  • Large sites with thousands of records
  • User created content
  • Data change often
  • Data driven apps, like CRMs
  • ...

@vueschool_io

Static Site Generation with Nuxt

@vueschool_io

Nuxt School?

@vueschool_io

🍪

Challenging thoughts?

🧐

@vueschool_io

Education should be accessible 👩‍🎓

$20 🤑

@vueschool_io

The Vue.js community is awesome 🤩

@vueschool_io

Support your

open source software!

Evan You

patreon.com/evanyou

Chris Fritz

patreon.com/chrisvuefritz

Guillaume Chau

patreon.com/akryum

Nuxt.js

opencollective.com/nuxtjs

Supports

Alex - Static Site Generation is Awesome

By Rolf Haug

Alex - Static Site Generation is Awesome

Alex

  • 79