使用Visual Studio代码将TypeScript编译为JavaScript
我是NodeJS和TypeScript的新手,我想从设置我的项目文件夹开始。 我已经有我的tsconfig.json
{ "compilerOptions": { "outDir": "./build", "module": "commonjs", "target": "es5", "noImplicitAny" : false }, "files": [ "./src/**/*.ts" ], "exclude": [ "node_modules" ]}
和package.json
{ "name": "crm", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" }
这是我简单的目录结构:
crm/ |-src/ |- main/ |- app.ts
当我使用tsc命令编译它时,我预计编译的目录将会是
crm/ |-build/ |- main/ |- app.js |- src/ |- main/ |- app.ts
但结果是
crm |- build/ |- app.js |- src/ |- main/ |- app.ts
没有创build的主文件夹。
我不知道如果问题是在tsconfig.json或在TSC命令
你已经设定好了
"outDir": "./build",
在你的tsconfig.json和没有rootDir
。 在这里检查compilerOptions
设置所需的输出构buildpath。
"outDir": "./build", "rootDir": "./src"
你会得到
crm |- build/ |- main/ |- app.js
Src: 这个问题