打字稿开发环境
Typescript development environment
我从打字稿开始。我从一个空文件夹和 运行 这些命令开始设置我的打字稿开发。
npm init
npm install typescript
npm install @types/node
然后我做了一个tsconfig文件
npx tsc --init
我尝试更改 tsconfig.json 中的输出目录,例如 "outDir": "./dist"
、
但这似乎不起作用。 t运行spiled 文件仍在进入 src 文件夹。
我的文件夹结构如下:
root
|_ node_modules
|_ src
|_ index.ts
|_ dist
|_package.json
|_tsconfig.json
|_package-lock.json
这是 tsconfig.json 文件
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
the transpiled file is still coming into the src folder.
您还需要设置一个rootDir。在您的情况下,它应该是 "rootDir": "src"
.
只需使用tsc
。您只需指定一个文件。 TypeScript 并不担心让它本身作为一个模块工作,因为你不需要只有一个文件的模块。
哦,还有来自 cli 参考:
Transpile just the index.ts with the compiler defaults tsc index.ts
我从打字稿开始。我从一个空文件夹和 运行 这些命令开始设置我的打字稿开发。
npm init
npm install typescript
npm install @types/node
然后我做了一个tsconfig文件
npx tsc --init
我尝试更改 tsconfig.json 中的输出目录,例如 "outDir": "./dist"
、
但这似乎不起作用。 t运行spiled 文件仍在进入 src 文件夹。 我的文件夹结构如下:
root
|_ node_modules
|_ src
|_ index.ts
|_ dist
|_package.json
|_tsconfig.json
|_package-lock.json
这是 tsconfig.json 文件
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
the transpiled file is still coming into the src folder.
您还需要设置一个rootDir。在您的情况下,它应该是 "rootDir": "src"
.
只需使用tsc
。您只需指定一个文件。 TypeScript 并不担心让它本身作为一个模块工作,因为你不需要只有一个文件的模块。
哦,还有来自 cli 参考:
Transpile just the index.ts with the compiler defaults
tsc index.ts