文章内容
2020/7/24 17:40:02,作 者: 黄兵
angular robots.txt sitemap.xml
最近使用Chrome Lighthouse检查网站的时候,提示没有找到robots.txt文件,如何在Angular项目中设置robots.txt文件呢?
下面是具体步骤:
首先在src/目录下面新建robots.txt和sitemap.xml文件如下图所示:

之后设置angular.json文件,找到build节点下面的assets标签,加入如下内容:
angular.json:
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/SMSReceiveAmerica",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/robots.txt",
"src/sitemap.xml",
"src/ads.txt",
"src/assets"
],
},
}之后再次发布,这两个文件已经可以正常访问了。
参考资料:
1、Angular CLI: Add Sitemap.xml and Robots.txt File
黄兵个人博客原创。
评论列表