打字稿中的输出和目录结构

时间:2016-12-06 23:45:34

标签: typescript

假设我的项目具有给定的目录结构:

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中并从那里运行编译......没什么,只是无法解决这个问题。

3 个答案:

答案 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

:)