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

tsconfig-schema.json say:

Specifies a list of files to be excluded from compilation. The 'exclude' property only affects the files included via the 'include' property and not the 'files' property. Glob patterns require TypeScript version 2.0 or later.

working workaround for me:

tsconfig.json

  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ],
    "baseUrl": "",
    "paths": {
      "app/*": ["./src/app/*"]
    }
  },
  "include": [
    "src/*"
  ],
  "exclude": [
    "src/app/directory_1/*",
    "src/app/directory_2/*"
  ]
}

Ldnz avatar Jul 09 '18 18:07 Ldnz

This won’t work. In our case we want to put the TS file on the intermediate server and use the angular to build those files

rajeshwar-cloud avatar Jul 09 '18 18:07 rajeshwar-cloud

@raorajesh what is "intermediate server" in your case? could you explain with more details? i also use the angular to build those files and have three tsconfig files (common, browser and for universal server). only server config contains include/exclude section.

Ldnz avatar Jul 09 '18 18:07 Ldnz

I'm not able to replicate this in my application, Currently, our application has a structure like src->app->modules->user-management, I want to exclude user-management folder in prod build, how can I do this.

Below is the tsConfig. { "extends": "../tsconfig.json", "compilerOptions": { "outDir": "../out-tsc/app", "module": "es2015", "baseUrl": "", "types": [ "jquery" ] }, "exclude": [ "test.ts", "/*.spec.ts", "app/modules/user-managment//*" ] }

mistrykaran91 avatar Jul 25 '18 08:07 mistrykaran91

Specifying the exact path of the file was not working for me, I had to use a recursive match on the root of the file location. e.g. this is what SHOULD have worked

"exclude": [
    "src/test.ts",
    "**/*.spec.ts",
    "src/other-main.ts",
    "src/tsconfig.other.ts",
    "src/app/other-app.module.ts"
]

This is what DID work;

"exclude": [
    "src/test.ts",
    "**/*.spec.ts",
    "**/other-main.ts",
    "**/tsconfig.other.ts",
    "**/other-app.module.ts"
]

rmsmq avatar Aug 01 '18 00:08 rmsmq

It worked for me by adding the directory of the module in the exlude array of tsconfig.app AND removing the module reference from app.module

profanis avatar Aug 07 '18 13:08 profanis

For anyone that get to here: The key is that the path is relative to the location of the "tsconfig.app.json"

ddehghan avatar Aug 08 '18 00:08 ddehghan

Just leaving this comment here in case it helps someone.

I had to create a a RouterLinkDirectiveStub to stub the [routerLink] directive and wanted to ignore the file from linting.

To do this, I created a relative path to my folder containing the stub, in tsconfig.app.json:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "**/*.spec.ts",
    "./app/shared/testing/*.ts"
  ]
}

kriskanya avatar Sep 07 '18 23:09 kriskanya

Is there any way that I can exclude some files ONLY when "ng build --production"? I still need those files when "ng serve".

neorclynn avatar Sep 18 '18 07:09 neorclynn

Leaving this here for others who may experience "exclude" not working. You must also exclude files that import anything that is being excluded for it work.

For example if you exclude "exclude-me.component.ts" but it in a "routing.module.ts" file, then "exclude-me.component.ts" will not be excluded. You must also exclude the "routing.module.ts" file in addition to "exclude-me.component.ts"

tiingo avatar Feb 09 '19 03:02 tiingo

@neorclynn if you didn't find a solution until now: you can specify another tsconfig file when running build.

cdarken avatar Jul 11 '19 08:07 cdarken

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.