验证打字稿,但不要构建它

我有一个名为“__ 测试 __”的文件夹。

我希望它被验证为打字稿,但我不想构建该文件夹。(我不希望它进入dist文件夹)

我该怎么做?

好像我必须包括它,但不是真的......

我的 ts.config.json:

{
    "compilerOptions": {
        "module": "CommonJS",
        "target": "ES2017",
        "noImplicitAny": true,
        "preserveConstEnums": true,
        "outDir": "./dist",
        "sourceMap": true,
        "esModuleInterop": true,
        "resolveJsonModule": true
    },
    "include": ["src/**/*", "src/**/*.json", "__tests__/**/*"],
    "exclude": ["node_modules", "**/*.spec.ts"]
}

回答

您可以简单地noEmit在您的用例中使用该选项来不发出输出。

{
  "compilerOptions": {
    // ...
    "noEmit": true,
  }
}

更新仅在测试用例中发射

我认为您还可以为测试文件创建新的配置,以便include仅从当前的测试代码扩展。

tsconfig.test.json

{
  "extends": "./tsconfig.json",
  {
   "compilerOptions": {
      "noEmit": true,
    },
   "include": [
      "__tests__", // your test file
   ],
  }
}

package.json

{
  "scripts": {
    "build": "tsc",
    "test:typeCheck": "tsc --project tsconfig.test.json"
  }
}
  • 键入检查您的测试文件夹而不发出: npm run test:typeCheck
  • 运行构建以正常发出文件: npm build

以上是验证打字稿,但不要构建它的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>