{"id":1388,"date":"2018-02-09T08:33:58","date_gmt":"2018-02-09T07:33:58","guid":{"rendered":"https:\/\/blog.thecodecampus.de\/?p=1388"},"modified":"2023-12-20T20:19:26","modified_gmt":"2023-12-20T19:19:26","slug":"angular-cli-sitemap-robots-txt","status":"publish","type":"post","link":"https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/","title":{"rendered":"Angular CLI: Add Sitemap.xml and Robots.txt File"},"content":{"rendered":"<p>As a developer you may get the task adding a Sitemap and a robot.txt to your Angular project. This is quite easy if it is being built with <a href=\"https:\/\/cli.angular.io\">Angular CLI<\/a>.<\/p>\n<p>Copy the files next to the <span class=\"lang:default decode:true crayon-inline \">favicon.ico<\/span>\u00a0 into the <span class=\"lang:default decode:true crayon-inline \">\/src<\/span>\u00a0 folder of your Angular project.<\/p>\n<pre class=\"\">\u251c\u2500\u2500 src\r\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 sitemap.xml\r\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 favicon.ico\r\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 robots.txt<\/pre>\n<p>&nbsp;<\/p>\n<p>Now open up the <span class=\"lang:default decode:true crayon-inline \">angular.json<\/span> file in the projects root folder with an editor and add the two files inside the <span class=\"lang:default decode:true crayon-inline \">assets<\/span>\u00a0section, as follows:<\/p>\n<pre class=\"lang:js decode:true \" title=\"angular.json\">{\r\n  \"$schema\": \".\/node_modules\/@angular\/cli\/lib\/config\/schema.json\",\r\n  \"version\": 1,\r\n  \"newProjectRoot\": \"projects\",\r\n  \"projects\": {\r\n    \"my-app\": {\r\n      \"__________comment\": \"[...]\",\r\n      \"architect\": {\r\n        \"build\": {\r\n          \"builder\": \"@angular-devkit\/build-angular:browser\",\r\n          \"options\": {\r\n            \"__________comment\": \"[...]\",\r\n            \"assets\": [\r\n              \"src\/favicon.ico\",\r\n              \"src\/robots.txt\",\r\n              \"src\/sitemap.xml\",\r\n              \"src\/assets\"              \r\n            ],\r\n          },\r\n          \"__________comment\": \"[...]\",\r\n        }\r\n      }\r\n    }\r\n  },\r\n}<\/pre>\n<p>If you have <a href=\"https:\/\/stedolan.github.io\/jq\/\" target=\"_blank\" rel=\"noopener\">jq<\/a> installed on your system you can achieve the same by executing the following one-liner without using an editor:<\/p>\n<pre class=\"lang:bash decode:true \" title=\"one-liner adding robots.txt to angular.json\">pn=`jq -r '.defaultProject' angular.json` &amp;&amp; \\\r\njq --arg pn \"$pn\" '.projects[$pn].architect.build.options.assets  += [ \"src\/sitemap.xmp\", \"src\/robots.txt\" ]'  angular.json &gt; angular.json.new &amp;&amp; \\\r\nmv angular.json.new angular.json\r\n<\/pre>\n<p>Restart your Angular build and the files should be served directly from the root path.<\/p>\n<p>If you still use version 1.x of the\u00a0<span class=\"lang:default decode:true crayon-inline \">@angular\/cli<\/span> then change\u00a0<span class=\"lang:default decode:true crayon-inline\">.angular-cli.json<\/span> instead of <span class=\"lang:default decode:true crayon-inline \">angular.json<\/span>\u00a0accordingly:<\/p>\n<pre class=\"lang:js decode:true\" title=\".angular-cli.json\">\"apps\": [\r\n    {\r\n     [...]\r\n      \"assets\": [\r\n        \"assets\",\r\n        \"favicon.ico\",\r\n        \"sitemap.xml\",\r\n        \"robots.txt\"\r\n      ],\r\n     [...]\r\n    }\r\n  ],<\/pre>\n<p>&nbsp;<\/p>\n<p>Another not very known feature of the CLI version 6.x is to relocate those assets. So alternatively you can leave your files beneath the <span class=\"lang:default decode:true crayon-inline \">\/src\/assets<\/span> folder and relocate them using the following configuration:<\/p>\n<pre class=\"lang:js decode:true\" title=\"relocate files\">\"assets\": [\r\n   \"src\/favicon.ico\",\r\n   \"src\/assets\",\r\n   {\"glob\": \"robots.txt\", \"input\": \"src\/assets\", \"output\": \"\/\"},\r\n   {\"glob\": \"sitemap.xml\", \"input\": \"src\/assets\", \"output\": \"\/\"}\r\n]\r\n<\/pre>\n<p>But keep in mind that these two files may be duplicated using this setting. Both files will be then\u00a0 available in the root and in the assets folder.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a developer you may get the task adding a Sitemap and a robot.txt to your Angular project. This is quite easy if it is being built with Angular CLI. Copy the files next to the favicon.ico\u00a0 into the \/src\u00a0 folder of your Angular project. \u251c\u2500\u2500 src \u2502\u00a0\u00a0 \u251c\u2500\u2500 sitemap.xml \u2502\u00a0\u00a0 \u251c\u2500\u2500 favicon.ico \u2502\u00a0\u00a0 \u251c\u2500\u2500 [&#8230;]<br \/><a class=\"meta-big\" href=\"https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/\"> READ MORE<\/a><\/p>\n","protected":false},"author":29,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"class_list":["post-1388","post","type-post","status-publish","format-standard","hentry","category-angular"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Angular CLI: Add Sitemap.xml and Robots.txt File - Web Development Blog<\/title>\n<meta name=\"description\" content=\"Optimize SEO effortlessly! Generate sitemap, robots.txt with Angular CLI. Elevate search visibility, boost rankings. Supercharge your strategy!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Angular CLI: Add Sitemap.xml and Robots.txt File - Web Development Blog\" \/>\n<meta property=\"og:description\" content=\"Optimize SEO effortlessly! Generate sitemap, robots.txt with Angular CLI. Elevate search visibility, boost rankings. Supercharge your strategy!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Development tips and tricks - theCodeCampus Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-09T07:33:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-20T19:19:26+00:00\" \/>\n<meta name=\"author\" content=\"theCodeCampus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"theCodeCampus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/angular-cli-sitemap-robots-txt\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/angular-cli-sitemap-robots-txt\\\/\"},\"author\":{\"name\":\"theCodeCampus\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#\\\/schema\\\/person\\\/276bbda2f8da73154f22fb652201cfbc\"},\"headline\":\"Angular CLI: Add Sitemap.xml and Robots.txt File\",\"datePublished\":\"2018-02-09T07:33:58+00:00\",\"dateModified\":\"2023-12-20T19:19:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/angular-cli-sitemap-robots-txt\\\/\"},\"wordCount\":202,\"commentCount\":10,\"publisher\":{\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#organization\"},\"articleSection\":[\"Angular\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/angular-cli-sitemap-robots-txt\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/angular-cli-sitemap-robots-txt\\\/\",\"url\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/angular-cli-sitemap-robots-txt\\\/\",\"name\":\"Angular CLI: Add Sitemap.xml and Robots.txt File - Web Development Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#website\"},\"datePublished\":\"2018-02-09T07:33:58+00:00\",\"dateModified\":\"2023-12-20T19:19:26+00:00\",\"description\":\"Optimize SEO effortlessly! Generate sitemap, robots.txt with Angular CLI. Elevate search visibility, boost rankings. Supercharge your strategy!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/angular-cli-sitemap-robots-txt\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/angular-cli-sitemap-robots-txt\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/angular-cli-sitemap-robots-txt\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Angular CLI: Add Sitemap.xml and Robots.txt File\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/\",\"name\":\"Web Development tips and tricks - theCodeCampus Blog\",\"description\":\"Tips, tricks, and experiences about developing web and mobile applications with Angular, TypeScript, and Testing.\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#organization\",\"name\":\"theCodeCampus\",\"url\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/TCC-Logo-Bildmarke-quadratisch.jpg\",\"contentUrl\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/TCC-Logo-Bildmarke-quadratisch.jpg\",\"width\":156,\"height\":156,\"caption\":\"theCodeCampus\"},\"image\":{\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#\\\/schema\\\/person\\\/276bbda2f8da73154f22fb652201cfbc\",\"name\":\"theCodeCampus\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/TCC-Logo-Bildmarke-quadratisch-96x96.jpg\",\"url\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/TCC-Logo-Bildmarke-quadratisch-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/TCC-Logo-Bildmarke-quadratisch-96x96.jpg\",\"caption\":\"theCodeCampus\"},\"description\":\"Our knowledge is not simply gained through reading - it is trained, tested and constantly being expanded. Because first and foremost, we are all developers at W11K. The know-how that we acquire here as developers, consultants and information architects flows immediately into our training courses and articles for theCodeCampus.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/showcase\\\/thecodecampus\\\/\"],\"url\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Angular CLI: Add Sitemap.xml and Robots.txt File - Web Development Blog","description":"Optimize SEO effortlessly! Generate sitemap, robots.txt with Angular CLI. Elevate search visibility, boost rankings. Supercharge your strategy!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/","og_locale":"en_US","og_type":"article","og_title":"Angular CLI: Add Sitemap.xml and Robots.txt File - Web Development Blog","og_description":"Optimize SEO effortlessly! Generate sitemap, robots.txt with Angular CLI. Elevate search visibility, boost rankings. Supercharge your strategy!","og_url":"https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/","og_site_name":"Web Development tips and tricks - theCodeCampus Blog","article_published_time":"2018-02-09T07:33:58+00:00","article_modified_time":"2023-12-20T19:19:26+00:00","author":"theCodeCampus","twitter_card":"summary_large_image","twitter_misc":{"Written by":"theCodeCampus","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/#article","isPartOf":{"@id":"https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/"},"author":{"name":"theCodeCampus","@id":"https:\/\/www.thecodecampus.de\/blog\/#\/schema\/person\/276bbda2f8da73154f22fb652201cfbc"},"headline":"Angular CLI: Add Sitemap.xml and Robots.txt File","datePublished":"2018-02-09T07:33:58+00:00","dateModified":"2023-12-20T19:19:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/"},"wordCount":202,"commentCount":10,"publisher":{"@id":"https:\/\/www.thecodecampus.de\/blog\/#organization"},"articleSection":["Angular"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/","url":"https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/","name":"Angular CLI: Add Sitemap.xml and Robots.txt File - Web Development Blog","isPartOf":{"@id":"https:\/\/www.thecodecampus.de\/blog\/#website"},"datePublished":"2018-02-09T07:33:58+00:00","dateModified":"2023-12-20T19:19:26+00:00","description":"Optimize SEO effortlessly! Generate sitemap, robots.txt with Angular CLI. Elevate search visibility, boost rankings. Supercharge your strategy!","breadcrumb":{"@id":"https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.thecodecampus.de\/blog\/angular-cli-sitemap-robots-txt\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.thecodecampus.de\/blog\/"},{"@type":"ListItem","position":2,"name":"Angular CLI: Add Sitemap.xml and Robots.txt File"}]},{"@type":"WebSite","@id":"https:\/\/www.thecodecampus.de\/blog\/#website","url":"https:\/\/www.thecodecampus.de\/blog\/","name":"Web Development tips and tricks - theCodeCampus Blog","description":"Tips, tricks, and experiences about developing web and mobile applications with Angular, TypeScript, and Testing.","publisher":{"@id":"https:\/\/www.thecodecampus.de\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.thecodecampus.de\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.thecodecampus.de\/blog\/#organization","name":"theCodeCampus","url":"https:\/\/www.thecodecampus.de\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.thecodecampus.de\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.thecodecampus.de\/blog\/wp-content\/uploads\/2024\/01\/TCC-Logo-Bildmarke-quadratisch.jpg","contentUrl":"https:\/\/www.thecodecampus.de\/blog\/wp-content\/uploads\/2024\/01\/TCC-Logo-Bildmarke-quadratisch.jpg","width":156,"height":156,"caption":"theCodeCampus"},"image":{"@id":"https:\/\/www.thecodecampus.de\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.thecodecampus.de\/blog\/#\/schema\/person\/276bbda2f8da73154f22fb652201cfbc","name":"theCodeCampus","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.thecodecampus.de\/blog\/wp-content\/uploads\/2024\/01\/TCC-Logo-Bildmarke-quadratisch-96x96.jpg","url":"https:\/\/www.thecodecampus.de\/blog\/wp-content\/uploads\/2024\/01\/TCC-Logo-Bildmarke-quadratisch-96x96.jpg","contentUrl":"https:\/\/www.thecodecampus.de\/blog\/wp-content\/uploads\/2024\/01\/TCC-Logo-Bildmarke-quadratisch-96x96.jpg","caption":"theCodeCampus"},"description":"Our knowledge is not simply gained through reading - it is trained, tested and constantly being expanded. Because first and foremost, we are all developers at W11K. The know-how that we acquire here as developers, consultants and information architects flows immediately into our training courses and articles for theCodeCampus.","sameAs":["https:\/\/www.linkedin.com\/showcase\/thecodecampus\/"],"url":"https:\/\/www.thecodecampus.de\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/posts\/1388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/comments?post=1388"}],"version-history":[{"count":8,"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/posts\/1388\/revisions"}],"predecessor-version":[{"id":2603,"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/posts\/1388\/revisions\/2603"}],"wp:attachment":[{"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/media?parent=1388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/categories?post=1388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/tags?post=1388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}