【问题标题】:Typescript keep subdirectories while building打字稿在构建时保留子目录
【发布时间】:2016-08-05 09:32:35
【问题描述】:

我一直在按照教程尝试让 Typescript 与 Angular 2 一起工作。问题是我似乎无法编译子目录并保留子目录。

我的 tsconfig.json

{
    "compilerOptions": {
        "target": "ES5",
        "module": "commonjs",
        "outDir": "build",
        "sourceMap": true,
        "sourceRoot": "src",

        "experimentalDecorators": true,
        "noEmitOnError": true,
        "noImplicitAny": true,
        "removeComments": false

    },
    "exclude": [
        "build",
        "client",
        "GulpTasks",
        "node_modules",
        "typings"
    ]
}

现在我的源代码有不同的模块和项目的客户端/服务器文件夹。

+build
+node_modules
+src
 ---+client
      ---+dir1
         ---+file1.ts
      ---+dir2
 ---+server
    ---+file1.ts
+typings

我需要在编译时保留目录结构,但是在子目录 (src/server) 中找到的文件在移动到构建文件夹时不会保留服务器子目录文件夹。没有 build/server/file1.js,只是 build/file1.js。

如何配置 tsc 在编写 JS 文件时使用子目录移动文件?我在 src/client/dir1 中有一些文件与 server/dir1 文件同名,并且不能覆盖另一个。

【问题讨论】:

    标签: typescript


    【解决方案1】:

    看起来您应该设置“rootDir”以获得所需的效果并至少使用 typescript 1.7。

    {
        "compilerOptions": {
            "target": "ES5",
            "module": "commonjs",
            "outDir": "build",
            "sourceMap": true,
            "rootDir": "src",
    
            "experimentalDecorators": true,
            "noEmitOnError": true,
            "noImplicitAny": true,
            "removeComments": false
    
        },
        "exclude": [
            "build",
            "client",
            "GulpTasks",
            "node_modules",
            "typings"
       ]
    }
    

    在 github 上查看以下问题:link

    【讨论】:

      猜你喜欢
      • 2015-09-03
      • 2022-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多