In order to copy any file like a favicon.ico
or a web.config
from my Angular CLI project out to my dist folder upon running my production build command: ng build --env=prod
, where do I have to put my file that I want copied and do I need to reference it in my .angular-cli.json
file?
Asked
Active
Viewed 3,103 times
6

Eric Bishard
- 5,201
- 7
- 51
- 75
1 Answers
11
A few things you must remember when outputting files to your dist directory.
Ensure that the file you want exported already exists in your src
directory. If you have both a favicon.ico
and a web.config
file that you want to output to the root of the dist
directory they need to be in the root of your src
directory.
Next you need to make a change to .angular-cli.json
like so:
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico",
"web.config"
],
...
}
],

Eric Bishard
- 5,201
- 7
- 51
- 75
-
1Just a note that I did as suggested but I got following error after trying to build the app "An unhandled exception occurred: The web.config asset path must start with the project source root." I added full path like "src/web.config" and it worked. Thanks Eric p.s. to all readers which had a problem with page refresh, if hosting on IIS, ensure that you set url with backslash like this url="\index.html". – sosNiLa Aug 24 '20 at 14:25
-
1Yes, this works, but does need the "src/" in the paths. Also a note for tuture readers, the file is called angular.json since Angular 6. – Tuukka Haapaniemi Feb 05 '21 at 08:24