假设我的项目具有给定的目录结构:
project
| app
| dist
| src
| components
| some .ts files
| services
| some .ts files
| some ts files
我想在dist中输入typescript编译的输出,但是从app开始具有相同的结构。编译后我想要的例子
project
| app
| dist
| components
| some .js files
| services
| some .js files
| some js files
| src
| components
| some .ts files
| services
| some .ts files
| some ts files
但我尝试了用编译选项可以想到的所有可能的解决方案,我对dist文件夹的结果总是那样:
project
| app
| dist
| app
| src
| components
| some .js files
| services
| some .js files
| some js files
我的tsconfig.json文件:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"outDir": "app/lib"
},
"exclude": [
"node_modules/*"
]
}
我尝试了很多解决方案,比如玩outDir,把我的tsconfig放在app / src中并从那里运行编译......没什么,只是无法解决这个问题。
答案 0 :(得分:1)
在compilerOptions中提供"rootDir": "./src"
答案 1 :(得分:0)
这是我的一个项目的tsconfig.json
,它完全符合您的要求:(将build
替换为dist
)
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"noEmitOnError": true,
"noImplicitAny": true,
"experimentalDecorators": true,
"sourceMap": true,
"sourceRoot": "src",
"outDir": "build"
},
"exclude": [
"build",
"node_modules"
]
}
答案 2 :(得分:0)
如Nikhil Yeole所说的
"rootDir": {
"description": "Specifies the root directory of input files. Use to control the output directory structure with --outDir.",
"type": "string"
}
有关属性的完整列表,请参见此处: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/tsconfig.json
:)