如何在typescript文件位于'./src'时构建输出文件夹

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

本文关键字:src 构建 输出 文件夹 文件 typescript      更新时间:2023-09-26

我有什么:

./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运行测试时产生问题?)

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

TypeScript没有很好地建模来处理绑定。这是你应该用其他工具来做的 <标题>更多h1> Webpack快速入门:https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html

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