Reputation: 10181
Is there any way to have the TypeScript compiler also copy content files that don't have a ts or tsx extension to the output directory?
For example, my tsconfig.json looks like:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"sourceMap": true,
"outDir": "../../dist",
"types": [
]
},
"include": [
"file1.ts",
"config.json"
],
"exclude": [
"../../node_modules"
]
}
I would like the config.json
to end up in my ../../dist directory, but this isn't happening. Is there no concept of a content file for TypeScript?
Upvotes: 69
Views: 61016
Reputation: 561
I was having the same problem and the solution for this was to add:
"source-path/**/*.json"
keeping into "includes" array:
"source-path/**/*"
Example:
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"resolveJsonModule": true,
"incremental": true
},
"include":[
"src/**/*",
"src/**/*.json",
],
}
Upvotes: 17
Reputation: 3733
This can be achieved by setting "resolveJsonModule": true
in the compiler options and adding "source-path/**/*.json"
to the include
array in the tsconfig.json
Upvotes: 169
Reputation: 533
One workaround is to make the json file a normal js file, require/import it normally, and add "allowJs" : true
to "compilerOptions" in tsconfig.json.
Upvotes: 4
Reputation: 452
No, the tsc
command's job is only to compile .ts files. It doesn't have the capabilities to do build-related tasks that a build system like gulp, grunt or webpack would handle.
For more information, see this similar question: Angular 2 + Typescript compiler copy html and css files
Upvotes: 0