配置中的Angular set build命令行参数(--host / --disable-host-check for --configuration = production)

问题描述 投票:1回答:1

当我在服务器上启动Angular项目时,我总是需要添加--disable-host-check和--host = 0.0.0.0才能工作。由于我不需要在我的本地开发环境中这样做,我想在angular.json构建配置中配置这些参数,以便我可以简单地执行

ng serve --prod 

要么

ng serve --configuration=staging 

在我的服务器上,并在相应的构建设置中自动设置主机和disable-host-check。那可能吗?目前我的配置如下所示:

"configurations": {
        "develop": { 
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.dev.ts"
            }
          ]
        },
        "staging": {
           "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.staging.ts"
            }
          ]
         }
        "production": { 
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.prod.ts"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "extractCss": true,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": true,
          "vendorChunk": false,
          "buildOptimizer": true,
          "budgets": [
            {
              "type": "initial",
              "maximumWarning": "2mb",
              "maximumError": "5mb"
            }
          ]
        }
angular deployment build environment serve
1个回答
1
投票

而不是搞乱angular.json文件为什么不在package.json中添加命令的脚本?例如:

  "scripts": {
    "start": "ng serve --prod --disable-host-check --host=0.0.0.0",
  }

然后调用它只是npm run start。

© www.soinside.com 2019 - 2024. All rights reserved.