{"id":183,"date":"2018-05-25T19:35:00","date_gmt":"2018-05-25T17:35:00","guid":{"rendered":"https:\/\/celilsemi.erkiner.com\/blog\/?p=183"},"modified":"2020-05-25T19:57:40","modified_gmt":"2020-05-25T17:57:40","slug":"serving-static-files-in-angular-projects","status":"publish","type":"post","link":"https:\/\/celilsemi.erkiner.com\/blog\/serving-static-files-in-angular-projects\/","title":{"rendered":"Serving Static Files in Angular Projects"},"content":{"rendered":"\n<p>Let&#8217;s say you have a JSON file in the root directory that you don&#8217;t want to be included in the compilation but copied over to distribution. In other words, you would not want this file to be combined with another file, modified or reduced in any way, but still included and presented in the angular application.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:false,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;null&quot;,&quot;mime&quot;:&quot;text\/plain&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Plain Text&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;text&quot;}\">\/src\n  |-- \/app\n  |-- \/assets\n  |-- index.html\n  |-- this_file.json<\/pre><\/div>\n\n\n\n<p>This means&nbsp;<code>http:\/\/example.com\/this_file.json<\/code>&nbsp;should be available to access after deployment and serve the <code>this_file.json<\/code>&nbsp;file as-is. <\/p>\n\n\n\n<p>This can be a <code>favicon.ico<\/code> file for bookmarks or a <code>manifest.json<\/code> file for progressive web applications.<\/p>\n\n\n\n<p>In this case, you can easily do this with a basic angular configuration via editing <code>angular.json<\/code> file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is angular.json?<\/h2>\n\n\n\n<p>A file named <code>angular.json<\/code> at the root level of an Angular workspace provides workspace-wide and project-specific configuration defaults for build and development tools provided by the Angular CLI.<\/p>\n\n\n\n<p>At the top level of\u00a0<code>angular.json<\/code>, a few properties configure the workspace, and a\u00a0<code>projects<\/code>\u00a0section contains the remaining per-project configuration options. CLI defaults set at the workspace level can be overridden by defaults set at the project level, and defaults set at the project level can be overridden on the command line.<\/p>\n\n\n\n<p>In this file, it is possible to manage assets to be included in application. Each\u00a0<code>build<\/code>\u00a0target configuration can include an\u00a0<code>assets<\/code>\u00a0array that lists files or folders you want to copy as-is when building your project. By default, the\u00a0<code>src\/assets\/<\/code>\u00a0folder and\u00a0<code>src\/favicon.ico<\/code>\u00a0are copied over.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:false,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;application\/json&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JSON&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;json&quot;}\">&quot;assets&quot;: [\n  &quot;src\/assets&quot;,\n  &quot;src\/favicon.ico&quot;\n]<\/pre><\/div>\n\n\n\n<p>You can further configure assets to be copied by specifying assets as objects, rather than as simple paths relative to the workspace root.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:false,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;application\/json&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JSON&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;json&quot;}\">&quot;assets&quot;: [\n  { &quot;glob&quot;: &quot;**\/*&quot;, &quot;input&quot;: &quot;src\/assets\/&quot;, &quot;output&quot;: &quot;\/assets\/&quot; },\n  { &quot;glob&quot;: &quot;favicon.ico&quot;, &quot;input&quot;: &quot;src\/&quot;, &quot;output&quot;: &quot;\/&quot; }\n]<\/pre><\/div>\n\n\n\n<p>Any files or directories you include in the asset value array will be served statically. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Serving Static File with Angular Application<\/h2>\n\n\n\n<p>Let&#8217;s use this configuration technique to serve the JSON file. <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:false,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;application\/json&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JSON&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;json&quot;}\">&quot;projects&quot;: {\n  &quot;YourProject&quot;: {\n      &quot;root&quot;: &quot;&quot;,\n      ...\n      &quot;architect&quot;: {\n        &quot;build&quot;: {\n          &quot;builder&quot;: &quot;@angular-devkit\/build-angular:browser&quot;,\n          &quot;options&quot;: {\n            ...\n            &quot;assets&quot;: [\n              ...\n              {\n                &quot;glob&quot;: &quot;this_file.json&quot;,\n                &quot;input&quot;: &quot;src\/&quot;,\n                &quot;output&quot;: &quot;\/&quot;\n              },\n              ...\n            ]\n...<\/pre><\/div>\n\n\n\n<p>Here is a page for more information;&nbsp;<a href=\"https:\/\/angular.io\/guide\/workspace-config#asset-config\">https:\/\/angular.io\/guide\/workspace-config#asset-config<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s say you have a JSON file in the root directory that you don&#8217;t want to be included in the compilation but copied over to distribution. In other words, you would not want this file to be combined with another file, modified or reduced in any way, but still included and presented in the angular [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[7],"tags":[22,4,33],"class_list":["post-183","post","type-post","status-publish","format-standard","hentry","category-front-end","tag-angular","tag-javascript","tag-json"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/posts\/183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/comments?post=183"}],"version-history":[{"count":3,"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/posts\/183\/revisions"}],"predecessor-version":[{"id":373,"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/posts\/183\/revisions\/373"}],"wp:attachment":[{"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/media?parent=183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/categories?post=183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/celilsemi.erkiner.com\/blog\/wp-json\/wp\/v2\/tags?post=183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}