Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to include a directory on build, without it being in the assets folder?

I have an Angular 4 app that is embedded into a website. There are some shared files that are in the root of the server that I reference when embedded into the website. My issue is, I want to be able to reference those files that are on the server in my app when I am doing development so I copy that folder to the root of my angular app but when the app builds, that folder is not copied.

For example I have a folder called /media in my root on the same level as the /src folder. When I do an ng build or if I just save and view my app locally, the media app is not copied so I am not able to see it. Adding it to the /assets folder is not an option so I am trying to figure out how to copy additional files on build.

I have tried a setup in my angular.cli.json file like this: "assets": [ "assets", "../media", "favicon.ico", "favicon-test.ico", "../favicon-test-2.ico" ],

and when I run ng build I only see assets, favicon.ico and favicon-test.ico but I do NOT see the media directory or favicon-test-2.ico file.

like image 947
Kevin Sar Avatar asked Feb 04 '23 10:02

Kevin Sar


1 Answers

You can add custom folders to build by adding path in

Angular 5

Filename: .angular.cli.json

"apps": [
  {
    "root": "src",
    "outDir": "dist",
    "assets": [
      "assets",
      "myFolder2/", // custom folders 1
      "myfolder2/", // custom folders 2,
      "file.json"   // custom files
    ],
  }
]

Angular 6

Filename: angular.json

"architect": {
  "build": {
    "options: {
       "assets": [
         "assets",
         "myFolder2/", // custom folders 1
         "myfolder2/", // custom folders 2,
         "file.json"   // custom files
        ]
     }
   }
 }

the files and folders mentioned in assets array will be added to dist folder when you run ng build

like image 137
Sibiraj Avatar answered Mar 05 '23 17:03

Sibiraj