vue项目自动生成打包后所有页面sitemap

758 阅读1分钟

1.Sitemap简介

百度爬虫非常喜欢Sitemap,Sitemap协议使你能够告知搜索引擎网站中可供抓取的网址,sitemap的生成就是让搜索引擎更好的去访问网站从而给网站的收录产生一个好的作用。

2.安装

npm install sitemap-webpack-plugin --save-dev

3.页面配置

 在vue.config.js中配置
 
 const SitemapPlugin = require('sitemap-webpack-plugin').default;
 
 const paths=[{path:'/foo/'},{path:'/bar/'}]
 
 module.exports={
         configureWebpack: {
               plugins:[
                      new SitemapPlugin({
                      base: 'https://www.baidu.com/',
                      paths,
                      options: {
                        filename: 'sitemap.xml',
                        lastmod: true,
                        skipgzip:false,
                        changefreq: 'always',
                        priority: 0.4
                      }
                    })
               ]
         }
 }

4.项目build后在dist文件夹中便可找到sitemap.xml文件

详细介绍:www.npmjs.com/package/sit…