Issue
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'
Solution
You can't build ssr with a specific environment using npm run build:ssr
command. Because this command builds with production
environment by default as should be stated in the angular.json
config.
To do so, you have to change your build scripts in the package.json
.
"build:ssr": "ng build && ng run my-app:server",
"build:staging:ssr": "ng build --configuration=staging && ng run my-app:server:staging",
Now run npm run build:staging:ssr
Answered By - qai
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.