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?
Using exclude
property of tsconfig.json
(at root level), i.e.:
{ "exclude": [ "node_modules", "**/*.spec.ts" ] }
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With