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 ?
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/*"
]
}
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
@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.
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//*" ] }
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"
]
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
For anyone that get to here: The key is that the path is relative to the location of the "tsconfig.app.json"
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"
]
}
Is there any way that I can exclude some files ONLY when "ng build --production"? I still need those files when "ng serve".
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"
@neorclynn if you didn't find a solution until now: you can specify another tsconfig file when running build.
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.