[英]Angular 4. Remove file in production environment
我有 Angular 4 項目並且只在開發環境中使用我的一些文件(或類)。 但是如何從生產環境的構建中刪除它們(ng build --env=prod)?
謝謝。
生產環境使用AOT編譯,因此您可以通過在src
文件夾中創建一個名稱為tsconfig-aot.json
的文件來自定義構建選項(有關更多信息,請tsconfig-aot.json
of Time Compilation ),然后可以使用exclude
數組指定排除文件,例如:
"exclude": [
"test.ts",
"**/*.spec.ts"
]
您也可以在angular.json中使用"fileReplacements"
。 您必須在構建中添加該文件,然后再將其替換為任何內容,因此它將刪除該文件。
例如,如果我只想在生產環境中而不是在暫存環境中添加robots.txt
,則可以這樣寫-
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/Build",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/robots.txt",
"src/assets"
],
"styles": [
"node_modules/ionicons/dist/css/ionicons.css",
"node_modules/ngx-lightbox/lightbox.css",
"src/styles.css"
],
"scripts": [
"node_modules/prismjs/components/prism-typescript.js",
"src/assets/js/customerUserMenu.js"
]
},
"configurations": {
"production": {
"outputPath": "dist/Production",
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
},
"staging": {
"outputPath": "dist/MyprojectStaging",
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.staging.ts"
},
{
"replace": "src/robots.txt",
"with": ""
}
]
}
}
},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.