vue-cil 服务端预渲染 prerender-spa-plugin

众所周知单页面应用不利于SEO,为了解决这个问题网上所给出的2个解决方案
1、SSH服务器端渲染
2、预渲染
由于页面较少,且预渲染相对于SSH比较简单,于是选择预渲染页面,预渲染可以极大的提高网页访问速度。而且配合一些meat插件,基本可以满足SEO需求
下面就来简单介绍一下
在webpack.prod.conf

 
const PrerenderSpaPlugin = require('prerender-spa-plugin')
const webpackConfig = merge(baseWebpackConfig, {
plugins: [
  new CopyWebpackPlugin([
  {
   from: path.resolve(__dirname, '../static'),
   to: config.build.assetsSubDirectory,
  ignore: ['.*']
  }
  ]),
   new PrerenderSpaPlugin(
  //将渲染的文件放到dist目录下
   path.join(__dirname, '../dist'),
   //需要预渲染的路由信息
   [ '/','/index','/cjrl','/hqyc','/article','/subscribe'],
   // [ '/'],
  {
  //在一定时间后再捕获页面信息,使得页面数据信息加载完成
  captureAfterTime: 50000,
  //忽略打包错误
  ignoreJSErrors: true,
  phantomOptions: '--web-security=false',
  maxAttempts: 10,
  }
),
 
]
})
  

猜你喜欢

转载自www.cnblogs.com/youji8/p/9049306.html