How to exclude some files from ng build
Versions.
@angular/cli: 1.0.0-rc.0 node: 7.6.0 os: darwin x64 @angular/common: 2.4.8 @angular/compiler: 2.4.8 @angular/core: 2.4.8 @angular/forms: 2.4.8 @angular/http: 2.4.8 @angular/platform-browser: 2.4.8 @angular/platform-browser-dynamic: 2.4.8 @angular/router: 3.4.8 @angular/cli: 1.0.0-rc.0 @angular/compiler-cli: 2.4.8
How to exclude some files from ng build ? My case is I will replace some js file dynamically in docker volume. For that , I just want to ignore some files while building. Is that possible ?
Try to add them to the "exclude" section of your tsconfig
"exclude": [
"myexclude.ts"
]
@vimalprakashts can you elaborate a bit more please?
i added them to tsconfig but that didn't work :\
Closing as original author never got back.
@filipesilva for me I want to exclude 'core-js/es6/reflect' and 'core-js/es7/reflect' from ng build -prod but need them for ng test and ng build (without aot).
@playground you can try using the environment files for that. I should mention that in the future they won't be needed for dev/test even.
@filipesilva @playground I am curious - how do you exclude files in the environment files... is there an example? I know I probably missed it on the documentation or elsewhere :-).
@ralberts I simply have a polyfills-dev.ts and a polyfills-prod.ts, and in build script just copy the corresponding environment file into polyfills.ts
any solution here? exclude doesn't work. I need to exclude folder from ng build
@Viktor-Bredihin: As described by @ctrl-brk, when I add the relative path of my folder in the exclude section of ./src/tsconfig.app.json, the CLI build command excludes this folder.
Does this work for your?
While adding it there does exclude the files from the build, ng serve will still watch changes (even to those excluded files) and recompile.
Any way to avoid this?
@hpawe01 In my project I have 2 areas (admin, user). It's using the same shared module, so actually I have 2 apps in the same project. Then I want to build 2 different apps, so admin area should be on one server and user area on another. But I can't do that, cause while ng build - builds only needed modules (where u have routes), ng build --prod - builds everything in the project
any workaround here ?
maybe it's possible to exclude files something for specific environment at least?
This should not be closed. I have same problem, and here I find no solution and no workaround. I really think that "Closing as original author never got back." is not a reason to close an issue, as it is evident that other people experience same problems. Also issue is easily understandable and I don't see any reason for elaboration. When people need support for using Angular, and encounter this problem, they will come to this issue. Here they will see no problem solved, no workaround and many question with no answer. And it stays like that for months. You can at least give some feedback. This is not only example of prematurely closed issues for Angular I encountered, and it really bugs me. I really hope that team takes this in consideration, as it might happen that many people "never come back".
@ManojlovicMilos I have found it on my own. Here is the best solution - https://yakovfain.com/2017/04/06/angular-cli-multiple-apps-in-the-same-project/
I got it working, after some experimenting (since I as well couldn't find documentation).
Assuming you've got a structure src/app/... , and the file src/tsconfig.json,
then in tsconfig.json the syntax that works for me is:
{
"compilerOptions": {
"baseUrl": ".",
"mapRoot": "./",
etc bla bla ....
},
"exclude": [
"./app/system/services/data.original-service.ts",
"./app/backend/system/services/http-queue.service.ts",
"./app/backend/system/services/auth.service.ts",
"./app/backend/system/services/auth-local.service.ts"
]
}
Wim-van-der-Veen 's solution worked for me... my tsconfig.app.json =
{ "extends": "../tsconfig.json", "compilerOptions": { "outDir": "../out-tsc/app", "module": "es2015", "baseUrl": ".", "types": [] }, "exclude": [ "test.ts", "/*.spec.ts", "registration", "./app/registration/" ] }
...adding the dot in baseUrl did the job ... phew. the above excludes the whole 'registration' folder
Didn't work for me :( I'm trying to exclude some mock files that I use only on *.spec.ts, but AOT build keeps saying they are not included on any NgModule
When I tried using exclude for my .spec.ts files, my Jasmine tests stopped working because the tests weren't part of the compilation! Need to include the .spec.ts files in JIT build and exclude them for AOT build! How to exclude in AOT build only?