将TypeScript与tsconfig.json文件一起使用时,是否可以包含json文件? [英] Is it possible to include a json file when using TypeScript with a tsconfig.json file?
问题描述
有没有办法让TypeScript编译器也将没有ts或tsx扩展名的内容文件复制到输出目录?
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?
例如,我的tsconfig.json如下:
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"
]
}
我希望config.json
最终出现在我的../../dist目录中,但这没有发生.没有TypeScript内容文件的概念?
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?
推荐答案
这可以通过在编译器选项中设置"resolveJsonModule": true
并将"source-path/**/*.json"
添加到tsconfig.json
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
这篇关于将TypeScript与tsconfig.json文件一起使用时,是否可以包含json文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!