Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude files from build in Angular 2

How to exclude files from the Angular build using Angular-CLI. I've just added the path to exclude in the tsconfig.json and tsconfig.app.json files, but when I run ng serve, Angular is still trying to compile the files.

Any ideas?

like image 263
Matías González Avatar asked Jul 06 '17 15:07

Matías González


2 Answers

Using exclude property of tsconfig.json (at root level), i.e.:

{    "exclude": [        "node_modules",        "**/*.spec.ts"    ] } 
like image 123
Roman C Avatar answered Oct 12 '22 20:10

Roman C


In your angular.json file,edit the build section as follows :

...             "assets": [               "src/assets",               "src/favicon.ico"             ],             "styles": [               "src/styles.scss"             ],             "scripts": []           },           "configurations": {             "production": {               "assets": [                 {                   "glob": "**/*",                   "input": "src/assets/",                   "ignore": [                     "**/test.json",                     "**/test"                   ],                   "output": "/assets/"                 },                 {                   "glob": "favicon.ico",                   "input": "src/",                   "output": "/"                 }               ], ... 

This will still do the default imports required,but remove the specified files/directories(test.json & /test) when running ng build --prod,however they will still be available via ng serve,which is great for local development.

Remember to also exclude in your .gitignore file if you have sensitive information in those files.

I could not make it work when editing tsconfig.json,but the above worked like a charm!

Solution based on an example found here

like image 43
maverickkevin Avatar answered Oct 12 '22 20:10

maverickkevin