Reputation: 7350
I can't seem to find if and how it would be possible to use a different set of assets whenever I use the --prod
switch of ng build
.
The use case is that I have multiple projects with a common set of assets in a shared folder, so the configuration of each single project in angular.json is like this:
"assets": [
{
"glob": "**/*",
"input": "src/assets",
"output": "/assets/"
},
{
"glob": "**/*",
"input": "projects/project1/src/assets/",
"output": "/assets/"
}
],
...
"assets": [
{
"glob": "**/*",
"input": "src/assets",
"output": "/assets/"
},
{
"glob": "**/*",
"input": "projects/project2/src/assets/",
"output": "/assets/"
}
],
When making production builds, I would like to remove the common src/assets
path.
Is it possible?
Upvotes: 1
Views: 1891
Reputation: 7350
I think the answer was right under my nose: each configurations
object allows a redefined assets
property.
So my requirement's configuration is as simple as:
{
"configurations": {
"production": {
"assets": [
{
"glob": "**/*",
"input": "projects/project1/src/assets/",
"output": "/assets/"
}
],
...
}
}
It works like a charm.
Upvotes: 1
Reputation: 9121
You need check for setting up configuration. This configuration will help you to create different environment for your project. In your case project 2.
you need to set different environment on the angular.json
"project2": {
"fileReplacements": [
{
"replace": "", //project 1 folder
"with": "" // project 2 folder
},
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
}
after setup you can hit command
ng build --configuration project2
Note: you need to set necessary parameter in new environment like below
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
Detail official documentation link https://angular.io/guide/build
Upvotes: 1