tsconfig.json
在命令行输入 tsc --init ,这是 TypeScript 提供的初始化功能,会生成一个默认的 tsconfig.json 文件。
tsc --init
Created a new tsconfig.json with:
TS
target: es2016
module: commonjs
strict: true
esModuleInterop: true
skipLibCheck: true
forceConsistentCasingInFileNames: true
You can learn more at https://aka.ms/tsconfig.json
每一个 tsc 的命令行的选项,都可以作为这个 JSON 的一个字段来管理,例如 --outDir 和 --target 选项,在这个 JSON 文件里对应的就是:
{
"compilerOptions": {
"target": "es6",
"module": "es6",
"outDir": "./dist"
}
}
完整的选项可以查看 TypeScript 官网: tsconfig - typescriptlang
解读 tsconfig.json 基本配置
compilerOptions
compilerOptions 是 tsconfig.json 中最重要的配置选项之一,它允许我们指定 TypeScript 编译器的各种行为和设置。以下是一些常用的 compilerOptions 配置选项:
paths
paths 选项用于配置模块解析时的路径映射,可以帮助我们简化模块导入的路径。
"compilerOptions": {
"paths": {
"@/*": ["src/*"]
}
}

浙公网安备 33010602011771号