18 | The browser loaded this page at {{ loadTime }}.
20 |
21 |
22 |
23 |
24 |
45 |
--------------------------------------------------------------------------------
/nuxt.config.js:
--------------------------------------------------------------------------------
1 | // Load dotenv module so that .env environment variables are available within
2 | // this file.
3 | require('dotenv').config();
4 |
5 | export default {
6 | target: 'static',
7 | head: {
8 | htmlAttrs: {
9 | lang: 'en',
10 | },
11 | titleTemplate: '%s | Pre-Vue',
12 | meta: [
13 | {charset: 'utf-8'},
14 | {name: 'viewport', content: 'width=device-width, initial-scale=1.0'},
15 | {property: 'og:type', content: 'website'},
16 | {
17 | property: 'og:description',
18 | content: 'Pre-Vue is a simple example of a pre-rendered Vue website',
19 | },
20 | {
21 | property: 'og:image',
22 | content: 'https://pre-vue.web.app/images/logo.png',
23 | },
24 | ],
25 | link: [
26 | {
27 | rel: 'icon',
28 | type: 'image/x-icon',
29 | href: '/favicon.ico',
30 | },
31 | ],
32 | },
33 | buildModules: [
34 | '@nuxtjs/dotenv',
35 | [
36 | '@nuxtjs/google-analytics',
37 | {
38 | id: process.env.GOOGLE_ANALYTICS_ID,
39 | },
40 | ],
41 | ],
42 | modules: ['@nuxtjs/sitemap', '@nuxtjs/robots'],
43 | plugins: ['~/plugins/head'],
44 | sitemap: {
45 | hostname: 'https://pre-vue.web.app/',
46 | gzip: true,
47 | exclude: ['/404'],
48 | },
49 | robots: {
50 | sitemap: 'https://pre-vue.web.app/sitemap.xml',
51 | },
52 | };
53 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # pre-vue
2 |
3 | [](https://circleci.com/gh/mtlynch/pre-vue) [](LICENSE)
4 |
5 | ## Overview
6 |
7 | This is an example of a [Vue](https://vuejs.org) + [Nuxt](https://nuxtjs.org) configuration that generates a pre-rendered, static site.
8 |
9 | Instead of generating a normal single-page app, it generates a static page for every route on your site, making it easier for you to configure search engine optimization and social sharing.
10 |
11 | ## Features
12 |
13 | The following features are built-in to this project template:
14 |
15 | - Generates a sitemap (for SEO)
16 | - Generates a robots.txt (for SEO)
17 | - Supports unique `
` tags for each page (for SEO)
18 | - Adds unique opengraph tags to each page (for social sharing)
19 | - Adds Google Analytics support
20 | - Adds a favicon
21 | - Handles 404s
22 |
23 | ## Benefits of pre-rendering
24 |
25 | ### Search engine optimization
26 |
27 | The primary benefit of this configuration is that it makes it easier to improve your site's search engine optimization. With a traditional Vue SPA, you can't set per-page attributes like the `` tag or the `` tag, which search engines use to understand the structure of your website.
28 |
29 | With pre-rendering, you can configure all the per-page elements so that they're present in your site's HTML when search engines index it.
30 |
31 | ### Social sharing
32 |
33 | Another major drawback of SPAs is that they have poor support for social sharing. Sites like Twitter, Facebook, and Pinterest require your pages to have HTML `` tags present before any JavaScript loads. With a normal Vue SPA, this prevents you from having distinct social sharing cards for different pages.
34 |
35 | With pre-rendering, each page on your site can have its own set of `` tags, so you can customize the social sharing cards for all of your site's pages.
36 |
37 | ## Requirements
38 |
39 | - [Node.js](https://nodejs.org/en/download/) 14.x or higher
40 |
41 | ## Quick Start
42 |
43 | ```bash
44 | npm install
45 | npm run serve
46 | ```
47 |
48 | Visit [http://localhost:3700](http://localhost:3700) to see the site running.
49 |
50 | ## Deploying to production
51 |
52 | To pre-render your website, run
53 |
54 | ```bash
55 | npm install
56 | npm run build
57 | ```
58 |
59 | This will generate all the files for a static, pre-rendered version of your website under the `dist/` folder. You can upload these files to any service that suports static website hosting, such as:
60 |
61 | - [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html)
62 | - [Google Cloud Storage](https://cloud.google.com/storage/docs/hosting-static-website)
63 | - [Netlify](https://www.netlify.com/blog/2016/10/27/a-step-by-step-guide-deploying-a-static-site-or-single-page-app/)
64 |
65 | The [circleci-firebase](https://github.com/mtlynch/pre-vue/tree/circleci-firebase) branch of this repo includes an example configuration that automatically builds your site using Circle CI and deploys it to Firebase.
66 |
67 | ## Customization
68 |
69 | To customize this template for your project:
70 |
71 | 1. Find/replace "https://pre-vue.web.app" with your app's base URL.
72 | 1. Find/replace `pre-vue` with your repo name.
73 | 1. Update `.env` with your Google Analytics ID.
74 |
75 | ## Live Demo
76 |
77 | The live version of this project is at:
78 |
79 | - [https://pre-vue.web.app](https://pre-vue.web.app)
80 |
--------------------------------------------------------------------------------