Is it possible to include a json file when using TypeScript with a tsconfig.json file?

前端 未结 3 392
温柔的废话
温柔的废话 2021-01-03 18:45

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.jso

相关标签:
3条回答
  • 2021-01-03 18:51

    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

    0 讨论(0)
  • 2021-01-03 18:56

    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.

    0 讨论(0)
  • 2021-01-03 19:05

    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

    0 讨论(0)
提交回复
热议问题