tsconfig,当我使用多个rootDirs时,如何在构建时将结构src文件展平为dist

时间:2019-09-25 10:16:34

标签: typescript nestjs typeorm

我有一个嵌套的js应用,其类型为orm,并进行文件数据库迁移。适用于Windows。 我需要使src的结构扁平化以构建dist,然后添加文件夹迁移。 我有这个结构:

project/
  tsconfig.json
  tsconfig.build.json
  ormconfig.js
  migrations/
    **.file.ts
  src/
    app.module.ts
    main.ts
    common/
    modules/

我需要构建:

dist
  migrations/
  common/
  modules/
  app.module.d.ts
  app/module.js
  main.d.ts
  main.js

但是我有

dist
  migrstions/
  src/
  tsconfig.build.tsbuildinfo

我的tsconfig.json文件:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "rootDir": ".",
    "rootDirs": ["./src/*"]
  },
  "exclude": ["node_modules"]
}

我的ormconfig.js

module.exports = {
  type: process.env.DB_TYPE,
  host: process.env.DB_HOST,
  port: process.env.DB_PORT,
  username: process.env.DB_USERNAME,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  entities: ['src/**/entities/index.ts'],
  migrations: ['migrations/*.ts'],
  migrationsRun: false,
  synchronize: false,
  cli: {
    migrationsDir: 'migrations',
  },
  charset: 'utf8mb4',
};

T尝试在tsconfig中添加路径:(通过解决方案How to configure tsconfig.json to output files from multiple source folders to single flat outDir?),但这对我不起作用。

"compilerOptions": {
   ...
   "rootDir": "./src",
   "paths": {
      "@app/migrations": ["./migrations"]
    }
   ...
}

是否可以为这种结构配置tsconfig,或者唯一的解决方案是将migrations文件夹传输到src?

0 个答案:

没有答案