Angular2 tsconfig - 在构建

时间:2017-01-28 15:14:02

标签: angular typescript tsconfig

我正在开发一个Angular2库项目,该项目具有index.ts文件,该文件是主应用程序的入口点,test.ts是测试设置的入口点(启动Karma,导入测试.ts文件)。我的tsconfig.json文件(包含在下面)包含两个条目文件。这在开发和测试期间工作正常,但是当我运行构建时,还包括test.ts文件。如果我从test.ts数组中删除files文件,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"
}
...

1 个答案:

答案 0 :(得分:0)

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

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