1.0.1 • Published 2 years ago

@xxzt/prerender-plugin v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

1. 预渲染插件

提供 SPA 项目的预渲染,提高访问速度,有利于 SEO
此插件可在 webpack 和 vite 中使用

1.1. 安装

yarn add -D @xxzt/prerender-plugin

1.2. Vite 中使用

// vite.config.ts

import { defineConfig } from 'vite'
import prerender from '@xxzt/prerender-plugin/lib/vite.js'
import path from 'path'

export default defineConfig({
  // ...
  plugins: [
    prerender({
      executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
      staticDir: path.join(process.cwd(), 'dist'),
      routes: ['/', '/about/us'],
    }),
  ],
})

1.3. Webpack 中使用

// vue.config.js  或者 webpack.config.js

import PrerenderWebpackPlugin from '@xxzt/prerender-plugin/lib/webpack.js'
import path from 'path'

export default {
  // ...
  configureWebpack: {
    plugins: [
      new PrerenderWebpackPlugin({
        executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
        staticDir: path.join(process.cwd(), 'dist'),
        routes: ['/', '/about/us'],
      }),
    ],
  },
}

1.4. 配置选项

属性描述类型参考值 👉 👉默认值是否必填
executablePath因为本插件依赖了 puppeteer-core,不包含 Chromium,所以需要配置外部的 ChromiumstringMacOS 安装谷歌浏览器,可使用 /Applications/Google Chrome.app/Contents/MacOS/Google Chrome-
staticDir构建目录,生成文件直接覆盖构建目录, 默认读取根目录下的 dist 目录stringdistdist
routes需要预渲染的路由数,默认只渲染根路由组string[]'/', '/about/us''/'

1.5. 最后

欢迎提 issue 🍎 🍏 🍊 🍋 🍒 🍇 🍉 🍓 🍑