Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 如何将CommonJS文件用于tsconfig.json?_Typescript_Tsconfig - Fatal编程技术网

Typescript 如何将CommonJS文件用于tsconfig.json?

Typescript 如何将CommonJS文件用于tsconfig.json?,typescript,tsconfig,Typescript,Tsconfig,许多系统Mocha、ESLint、NYC都为您提供了一个选项,您希望配置文件的格式为commonjs/js、json、yml等 这可能会很有帮助,因为在使用module.exports的CommonJS中,您可以在配置文件中或配置文件中的其他代码中添加注释,这提供了很大的灵活性 有没有一种方法可以在TypeScript中使用CommonJS或module.exports来定义tsconfig文件,而不仅仅是一个json文件?我会将tsconfig.json保留为json,并在README.md中

许多系统Mocha、ESLint、NYC都为您提供了一个选项,您希望配置文件的格式为commonjs/js、json、yml等

这可能会很有帮助,因为在使用module.exports的CommonJS中,您可以在配置文件中或配置文件中的其他代码中添加注释,这提供了很大的灵活性

有没有一种方法可以在TypeScript中使用CommonJS或module.exports来定义tsconfig文件,而不仅仅是一个json文件?

我会将tsconfig.json保留为json,并在README.md中添加必要的注释

另一个选项是在json中添加注释,如下所示:

// tsconfig.json
{
  "//comment": "comment content",
  "compilerOptions": {
    ...
  },
}
如果需要更大的灵活性,可以添加构建步骤,从.js文件生成tsconfig.json

//tsconfig.js //注释或代码在这里 module.exports={ 编译器选项:{ 模块:commonjs, }, }; //tsconfigBuilder.js 常数fs=要求“fs”; const config=require'/tsconfig'; fs.writeFileSync'/tsconfig.json',json.stringifyconfig,null,2; 在package.json中添加脚本,以便在编译器步骤之前从tsconfig.js生成tsconfig.json

//package.json 脚本:{ build tsconfig:node tsconfig builder.js, ... }, 你完成了