[英]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"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.