Angular 在配置中设置构建命令行参数(--host / --disable-host-check for --configuration=production)

Angular set build command line parameter in config (--host / --disable-host-check for --configuration=production)

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

ng serve --prod 

ng serve --configuration=staging 

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

"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.json 文件,不如为 package.json 中的命令添加一个脚本?例如:

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

然后调用它就可以是 npm 运行 start.