我的项目文件夹目录是这样的
+ build
+ node_modules
+ server
+ config
+ api
+ database
+ ts-model
- server.ts
gitignore
app.js
package.json
tsconfig.ts
我的tsconfig.ts文件如下
{
"compilerOptions": {
"module": "none",
"target": "es2016",
"outDir": "build",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true
},
"include:": [
"server/**/*.ts"
],
"exclude": [
"node_modules"
]
}
问题是每当我运行npm run build时,我的build文件夹都不维护文件夹结构。 我的构建文件夹应该包含build>> server>> foldersInsideServer但它实际上是build>> foldersInsideServer
+ build
+ config
+ api
+ database
+ ts-model
- server.ts
我已经看到了一种行为,每当我创建另一个名为“test”的文件夹并将空ts文件放入其中时,那个时间构建就会生成这样的
+build
+server
+test
但是一旦删除测试文件夹,它就会再次停止生成服务器文件夹,但会显示服务器内的文件夹。如何在不创建具有空文件
的其他文件夹的情况下解决此问题答案 0 :(得分:1)
Add "rootDir": "./"
to your tsconfig.json
.
From the TypeScript wiki:
--outDir
specifies the "root" directory of the output. The compiler needs a "root" directory in the source to mirror into the output directory. If--rootDir
is not specified, the compiler will compute one; this is based on a common path calculation, which is the longest common prefix of all your input files. Obviously this changes with adding a new file to the compilation that has a shorter path prefix.To ensure the output does not change with adding new files specify
--rootDir
on the command-line or in your tsconfig.json