定义
在构建阶段生成匹配预渲染路径的 html 文件(注意:每个需要预渲染的路由都有一个对应的 html)。构建出来的 html 文件已有部分内容。
用途
预渲染prerender-spa-plugin配置生成多页面,解决首屏白屏问题,提升用户体验。同时配合 vue-meta-info 可以生成 title 和 meta 标签,可解决 SPA 页面的 SEO 痛点
使用
安装
1 | $ npm install prerender-spa-plugin --save |
目录结构
1 | ├── README.en.md |
配置文件
src/index.html
1 |
|
src/app.vue
1 | <template> |
src/index.js
1 | import Vue from "vue"; |
src/views/home/home.vue
1 | <template> |
src/views/login/login.vue
1 | <template> |
src/router/index.js
1 | import Vue from "vue"; |
webpack 配置
1 | ... |
构建之后的 index.html
1 |
|
原理
使用 Puppeteer
1 | (route, index) => |
类似这样子吧,拿到模板的内容
1 | const puppeteer = require("puppeteer"); |