美文网首页
node项目,使用typescript时,如何引用使用json文

node项目,使用typescript时,如何引用使用json文

作者: Again_21eb | 来源:发表于2021-07-24 16:12 被阅读0次
    之前为了找到答案花了很多时间。为了方便和我遇到一样问题的道友,以及日后的使用。特写一篇短文。
    
    答案很简单,只需要配置下tsconfig.json文件就行了,但是我很抱歉的告诉各位, [官方配置文档](https://www.tslang.cn/docs/handbook/tsconfig-json.html)。详情可以进入如下链接
    
    答案出自官网的文档版本 [Typescript2.9](https://www.tslang.cn/docs/release-notes/typescript-2.9.html)
    即添加compilerOptions配置项"resolveJsonModule": true即可。我的tsconfig.json如下
    
    {
      "compileOnSave": true,
      "compilerOptions": {
        "module": "commonjs",
        "declaration": true,
        "removeComments": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "allowSyntheticDefaultImports": true,
        "target": "es2017",
        "sourceMap": true,
        "outDir": "./dist",
        "baseUrl": "./",
        "incremental": true,
        "resolveJsonModule": true,
      }
    }
    

    相关文章

      网友评论

          本文标题:node项目,使用typescript时,如何引用使用json文

          本文链接:https://www.haomeiwen.com/subject/lmhvmltx.html