最初,我在Angular 2.4.0和webpack
上使用Angular VS 2017模板。Angular-CLI - 如何在分發之前替換文件中的某些字符串,基於環境
由於升級到Angular 4的一些問題,我決定切換到Angular-CLI(angular 4)和net.core 2.0應用程序。我的應用程序已設置並正在運行。
我使用TFS的建設,並根據環境我有我的角度應用幾個不同的設置文件:
- app.settings.debug.ts
- app.settings.release.ts
- app.settings.ts
我導入基於環境中,這些文件填寫驗證配置:
import { Injectable } from '@angular/core';
import { AppSettings } from '../../app.settings';
@Injectable()
export class AuthConfiguration {
// The Issuer Identifier for the OpenID Provider (which is typically obtained during Discovery) MUST exactly match the value of the iss (issuer) Claim.
public iss = AppSettings.API_AUTH_URL;
public server = AppSettings.API_AUTH_URL;
public redirect_url = AppSettings.WEBAPP_URL;
// This is required to get the signing keys so that the signiture of the Jwt can be validated.
public jwks_url = AppSettings.API_AUTH_URL + '/.well-known/openid-configuration/jwks';
// The Client MUST validate that the aud (audience) Claim contains its client_id value registered at the Issuer identified by the iss (issuer) Claim as an audience.
// The ID Token MUST be rejected if the ID Token does not list the Client as a valid audience, or if it contains additional audiences not trusted by the Client.
public client_id = 'angular2client';
public response_type = 'id_token token';
public scope = 'api openid profile';
public post_logout_redirect_uri = AppSettings.WEBAPP_URL;
}
在舊的項目我使用的WebPack來代替這部分基於環境:
import { AppSettings } from '../../app.settings';
像這樣webpack.config.js:
{ test: /\.ts$/, include: /ClientApp/, use: [{ loader: 'string-replace-loader', query: { search: '/app.settings', replace: isLocalhost ? '/app.settings' : isDebug ? '/app.settings.debug' : '/app.settings.release' }, }, 'awesome-typescript-loader?silent=true', 'angular2-template-loader',] },
我如何與角度達到這個-CLI和packages.json?
我希望實現與現在一樣的行爲,其中TFS構建我有一個NPM任務,其中包含來自package.json的命令,例如分別爲每個環境的npm build debug
或npm build release
。
如果我想加載發佈文件,在這種情況下是environment.release.ts在service.ts文件中做任何更改都必須完成?或者IT保持相同的導入?在這種情況下,不需要字符串替換@AmelSalibasic相同的導入 –
。cli/webpack將處理使用什麼,所以導入總是'/ environments/environment' – LLai
我今天會嘗試,並且讓你知道很多 –