【发布时间】:2018-03-17 16:56:53
【问题描述】:
最初,我使用 Angular VS 2017 模板和 Angular 2.4.0 和 webpack。
由于升级到 Angular 4 的一些问题,我决定切换到 Angular-CLI(angular 4) 和 net.core 2.0 应用程序。我的应用程序已设置并正在运行。
我正在使用 TFS 进行构建,并且根据环境,我的 Angular 应用程序中有几个不同的设置文件:
- app.settings.debug.ts
- app.settings.release.ts
- app.settings.ts
我是根据环境导入这些文件来填写Auth Configuration:
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',] },
如何使用 angular-CLI 和 packages.json 实现这一点?
我希望实现与现在相同的行为,其中 TFS 构建我有一个 NPM 任务,使用 package.json 中的命令,例如,npm build debug 或 npm build release 分别用于每个环境。
【问题讨论】:
标签: angular tfs asp.net-core angular-cli