当打字稿文件位于'./src'时如何构建输出文件夹

How to build to output folder when the typescript files are located in './src'

我有:

./src/myfile.ts
./test/mytest.spec.ts

tsc应该在./build位置创建一个javascript(myfile.js)和定义文件(myfile.d.ts) .

我的tsconfig.ts:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "noImplicitAny": false,
    "rootDir": ".",
    "outDir": "./build",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "declaration": true
  },
  "files": [
    "./src/index.ts"
  ],
  "exclude": [
    ".vscode",
    ".git",
    "build",
    "node_modules",
    "test"
  ],
  "compileOnSave": false,
  "buildOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

但是此配置文件在 ./build/src/ 子文件夹中生成 myfile.js

请注意,我不能使用 "rootDir": "./src",因为测试文件夹未编译(当 运行 使用 karma + webpack 测试时会出现问题?)

And tsc should create a javascript (myfile.js) and definition file (myfile.d.ts) in the ./build location.

TypeScript 没有很好地建模来处理捆绑。这是你应该使用其他工具来做的事情

更多

例如Webpack 快速入门:https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html

不推荐 out / outFile : https://basarat.gitbooks.io/typescript/content/docs/tips/outFile.html