Reputation: 4984
The official handbook about tsconfig.json says:
The tsconfig.json file specifies the root files and the compiler options required to compile the project.
As far as I understand, the root files of tsconfig.json are the files that tsc
should compile by default (i.e. no files are passed explicitly). According to the handbook, I can use the "files" or "exclude" property to define the root files.
If no "files" property is present in a tsconfig.json, the compiler defaults to including all TypeScript (*.ts or *.tsx) files in the containing directory and subdirectories. When a "files" property is present, only the specified files are included.
If the "exclude" property is specified, the compiler includes all TypeScript (*.ts or *.tsx) files in the containing directory and subdirectories except for those files or folders that are excluded.
The "files" property cannot be used in conjunction with the "exclude" property. If both are specified then the "files" property takes precedence.
I'm not using tsc
directly. Instead, I'm using Webpack to compile my TypeScript files. Therefore, I'm using hjs-webpack which uses awesome-typescript-loader:
webpack.config.js
var getConfig = require('hjs-webpack');
var config = getConfig({
in: 'src/index.ts',
out: 'public',
clearBeforeBuild: true
});
module.exports = config;
I specify all entry points in my webpack.config.js. If I understand it right, awesome-typescript-loader tells tsc
that those entry files are the root files. That would mean that the "files" and "exclude" property of tsconfig.json are always ignored by tsc
. Is this right?
I often see an "exclude" property in jsconfig.json of Webpack projects. Best example is ts-loader (another TypeScript loader for Webpack), which mentions this configuration step:
- Add a tsconfig.json file.
{
"compilerOptions": {
"target": "es5",
"sourceMap": true
},
"exclude": [
"node_modules"
]
}
If "files" and "exclude" property of tsconfig.json are always ignored if only Webpack is used for compilation, why should I specify "files" or "exclude" property in tsconfig.json?
Please write a comment, if you need further information (e.g. about my setup) to answer the question.
Upvotes: 0
Views: 10086
Reputation: 7621
Yes if you are using webpack for compile then you don't need to include it, you simply point to your only ts files to be compiled. Your loader will look for the tsconfig file for compilation config. It's has no purpose in webapp.
here is an example of webpack angular2 typescript seed i'm working on
Upvotes: 3