Angular2 tsconfig - 在构建期间将文件排除为入口点

Angular2 tsconfig - Exclude file as entry point during build

我正在开发一个 Angular2 库项目,该项目有一个 index.ts 文件,它是主应用程序的入口点,还有一个 test.ts 文件,它是测试设置的入口点(启动 Karma,导入测试 .ts 文件)。我的 tsconfig.json 文件(包含在下面)包含两个条目文件。这在开发和测试期间工作正常,但是当我 运行 构建 test.ts 文件时也包括在内。如果我从 files 数组中删除 test.ts 文件,Webstorm 会将代码库中装饰器的每次使用都标记为错误 (experimental support for decorators is a feature that is subject to change in a future release...)。

有没有办法解决这个问题,让 IDE 使用 tsconfig.json 文件作为测试文件,但在构建时不包含它?

// tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "declaration": true,
    "stripInternal": true,
    "experimentalDecorators": true,
    "strictNullChecks": true,
    "noImplicitAny": true,
    "module": "es2015",
    "moduleResolution": "node",
    "paths": {
      "@angular/core": ["node_modules/@angular/core"],
      "@angular/testing": ["node_modules/@angular/testing"],
      "rxjs/*": ["node_modules/rxjs/*"]
    },
    "allowSyntheticDefaultImports": true,
    "rootDir": ".",
    "outDir": "dist",
    "sourceMap": true,
    "inlineSources": true,
    "target": "es5",
    "skipLibCheck": true,
    "lib": [
      "es2015", 
      "dom"
    ],
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "files": [
    "index.ts",
    "test.ts"
  ],
  "angularCompilerOptions": {
    "strictMetadataEmit": true
  }
}

*构建脚本供参考

// package.json

...
"scripts": {
    "cleanup": "rimraf dist/bundles dist/src dist/index.d.ts dist/index.js dist/index.js.map dist/LICENCE dist/README.md",
    "bundling": "rollup -c",
    "minify": "uglifyjs dist/bundles/my-library.umd.js --screw-ie8 --compress --mangle --comments --output dist/bundles/async-local-storage.umd.min.js",
    "copy": "copyfiles LICENSE README.md dist",
    "build": "npm run cleanup && ngc && npm run bundling && npm run minify && npm run copy"
}
...

已通过创建第二个 tsconfig 文件 (tsconfig.build.json) 并更新 build 脚本以使用该文件解决;

"build": "npm run cleanup && ngc -p tsconfig.build.json && npm run bundling && npm run minify && npm run copy"