vue预渲染方案
下载插件
npm install prerender-spa-plugin vue-meta-info
配置插件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
const PrerenderSPAPlugin = require('prerender-spa-plugin') const Renderer = PrerenderSPAPlugin.PuppeteerRenderer
const NODE_ENV = process.env.NODE_ENV
if (NODE_ENV === 'production') { webpackConfig.plugins.push( new PrerenderSPAPlugin({ staticDir: config.build.assetsRoot, routes: settings.prerenderRoutes, renderer: new Renderer({ inject: { foo: 'bar' }, headless: false, }) }) ) }
mounted() { document.dispatchEvent(new Event('custom-render-trigger')) }
|