Typescript编译器有时会忽略结构,但有时会保留文件夹结构?

Typescript编译器有时会忽略结构,但有时会保留文件夹结构?,typescript,tsc,Typescript,Tsc,typescript编译器应该将/下的文件编译到/build/,这些文件由几个目录组成,其中一个目录包含typescript源代码/src/。这是通过以下类型脚本配置完成的: { "compilerOptions": { /* Visit https://aka.ms/tsconfig.json to read more about this file */ /* Basic Options */ "target": &quo

typescript编译器应该将
/
下的文件编译到
/build/
,这些文件由几个目录组成,其中一个目录包含typescript源代码
/src/
。这是通过以下类型脚本配置完成的:

{
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig.json to read more about this file */

    /* Basic Options */
    "target": "es2019",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    "lib":  ["es2015","es2020"],                             /* Specify library files to be included in the compilation. */

    "sourceMap": true,                     /* Generates corresponding '.map' file. */
    "outDir": "build",                        /* Redirect output structure to the directory. */
    /* Strict Type-Checking Options */
    "strict": true,                           /* Enable all strict type-checking options. */
    "esModuleInterop": true,                  /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
 
    /* Advanced Options */
    "skipLibCheck": true,                     /* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true  /* Disallow inconsistently-cased references to the same file. */


  },
  "exclude": [
    ".idea",
    "build",
    "node_modules",
    "typings/globals",
    "typings/modules",
    "test"
  ]
}
现在我注意到最终的构建文件不再位于构建中的
src
目录中,而是位于主
/src/app.ts
目录中,它将被编译为
/build/app.js

这本身不是问题,我可以更改输出目录。但是,每当我从排除的目录中删除
test
目录(其中包含typescript)时。或者,当我添加第二个源目录时,编译不会突然将顶级目录展平

/src/app.ts
变成
/build/src/app.js

这使得进一步处理相当困难。所以我可以让它不去压平根目录吗?--即使显式地声明根目录也会导致这种“扁平化”。因此,将
/src/
指定为根目录之一将不起作用,因为如果该目录只包含一个子目录,并且带有typescript,则该目录本身可能会被压平