angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

How to exclude some files from ng build

Open vimalprakashts opened this issue 9 years ago • 32 comments

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 ?

vimalprakashts avatar Apr 24 '17 06:04 vimalprakashts

Try to add them to the "exclude" section of your tsconfig

  "exclude": [
    "myexclude.ts"
  ]

ctrl-brk avatar Apr 24 '17 15:04 ctrl-brk

@vimalprakashts can you elaborate a bit more please?

filipesilva avatar May 05 '17 16:05 filipesilva

i added them to tsconfig but that didn't work :\

wnabil avatar Jun 01 '17 09:06 wnabil

Closing as original author never got back.

filipesilva avatar Jun 12 '17 09:06 filipesilva

@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 avatar Aug 13 '17 10:08 playground

@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 avatar Aug 21 '17 10:08 filipesilva

@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 avatar Aug 31 '17 16:08 ralberts

@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

playground avatar Aug 31 '17 16:08 playground

any solution here? exclude doesn't work. I need to exclude folder from ng build

Viktor-Bredihin avatar Oct 01 '17 14:10 Viktor-Bredihin

@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?

hpawe01 avatar Nov 14 '17 16:11 hpawe01

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?

stweedie avatar Nov 30 '17 19:11 stweedie

@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

Viktor-Bredihin avatar Dec 20 '17 12:12 Viktor-Bredihin

any workaround here ?

Viktor-Bredihin avatar Dec 20 '17 12:12 Viktor-Bredihin

maybe it's possible to exclude files something for specific environment at least?

Viktor-Bredihin avatar Dec 20 '17 13:12 Viktor-Bredihin

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 avatar Dec 21 '17 13:12 ManojlovicMilos

@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/

Viktor-Bredihin avatar Dec 21 '17 16:12 Viktor-Bredihin

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 avatar Jan 05 '18 11:01 Wim-van-der-Veen

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

TimWarp avatar Mar 13 '18 15:03 TimWarp

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

gabrielalan avatar Mar 27 '18 16:03 gabrielalan

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?

FirstVertex avatar May 04 '18 14:05 FirstVertex