我正在开发一个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"
}
...
答案 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"