1

Usually, when I build simple SPAs, I use --c flag to select proper environment and put configs to angular.json inside configurations dict, that lives in build dict like so:

        "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"
                }
              ]
            }
          }
        }

How can I run SSR build with proper environment, when I use command npm run build:ssr?

I tried same scheme npm run build:ssr --c staging, but got error Unknown option: 'staging'

s_spirit
  • 111
  • 10
  • 1
    I think you're providing the c argument to npm instead of `build:ssr`. Can you try `npm run build:ssr -- --c staging`? https://stackoverflow.com/questions/43046885/what-does-do-when-running-an-npm-command – Pieterjan Jun 17 '20 at 10:25

1 Answers1

0

I think you typed the wrong command. You can run the command below:

 ng build -c staging

Or you can create the npm script in your package.json:

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

} and run the command below:

npm run build:ssr
joccafi
  • 78
  • 9