【问题标题】:Run ng build with custom configurations使用自定义配置运行 ng build
【发布时间】:2019-04-23 23:25:05
【问题描述】:

我有 Angular 项目,我想将它部署在 Apache 服务器上。我使用ng build,但我想为后端自定义地址和端点。

proxy.conf.json:

{
  "/api/*": {
    "target": "http://localhost:8080",
    "secure": false,
    "logLevel": "debug",
    "changeOrigin": true
  }
}

根本不应用此配置。 如何正确设置以更改配置?

环境ts文件:

import {environment as prod} from './environment.prod';

export const environment = Object.assign(prod, {
  production: false
});

【问题讨论】:

标签: angular typescript angular6 angular7


【解决方案1】:

假设您使用的是 Angular (>v6),并且您已根据要求创建了多个环境文件。

所以你需要做的是,转到 angular.json 文件

angular.json > projects > projectName > architect > build > configurations > fileReplacements

在这里你需要用你的文件名替换文件名 -

"replace": "src/environments/environment.ts",
"with": "src/environments/environment.live.ts"

【讨论】:

    【解决方案2】:

    您可以定义不同的环境文件。下面是“dev”的例子:

    export const environment = {
        production: false,
        envName: 'dev',
        configPath: './assets/config/config.dev.json'
        ...
    };
    

    在“angular.json”文件中为“dev”添加配置部分,如下所示:

    "dev": {
      "fileReplacements": [
        {
          "replace": "src/environments/environment.ts",
          "with": "src/environments/environment.dev.ts"
        }
      ],
      ....
    

    并使用此命令构建:ng build --configuration=dev

    欲了解更多信息,请查看此帖子:How to set environment via `ng serve` in Angular 6

    【讨论】:

      猜你喜欢
      • 2019-01-12
      • 2018-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-20
      • 2018-10-07
      • 2015-07-20
      • 1970-01-01
      相关资源
      最近更新 更多