【问题标题】:Select environment when build SSR app - Angular 9构建 SSR 应用程序时选择环境 - Angular 9
【发布时间】:2020-10-07 02:44:10
【问题描述】:

通常,当我构建简单的 SPA 时,我使用 --c 标志来选择适当的环境并将配置放入 angular.jsonconfigurations dict,它住在 build dict 中,如下所示:

        "build": {
          "configurations": {
            "staging": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.staging.ts"
                }
              ],
              "optimization": true,
              "aot": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ]
            },
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ]
            }
          }
        }

当我使用命令npm run build:ssr 时,如何在适当的环境下运行 SSR 构建?

我尝试了相同的方案npm run build:ssr --c staging,但得到了错误Unknown option: 'staging'

【问题讨论】:

标签: angular typescript server-side-rendering


【解决方案1】:

我认为你输入了错误的命令。您可以运行以下命令:

 ng build -c staging

或者您可以在package.json 中创建 npm 脚本:

  "scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"build:ssr": "ng build -c staging",

} 并运行以下命令:

npm run build:ssr

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 2017-01-30
    • 2019-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多