I used to replace template files by passing configurations earlier like this in angular.json file:
"fileReplacements": [
{
"replace": "global/components.abc.html",
"with": "global/components.def.html"
}
]
But now it's giving me errors on build:
Schema validation failed with the following errors:
Data path "/fileReplacements/2" must have required property 'src'.
Data path "/fileReplacements/2/replace" must match pattern "\.(([cm]?j|t)sx?|json)$".
Data path "/fileReplacements/2" must match exactly one schema in oneOf.
I went through some articles and found out that this has been the case since Angular CLI version 9. Previously however the offending file replacements were silently ignored.
A solution however is provided here: #14599 (comment) but it only provides a way to replace index.html files.
My question is there's a correct way to replace component template files? Any help is much appreciated.
fileReplacementsregexAs correctly pointed out, index is a special case,
and it is handled with the link provided in the question
I wanted to replace .htaccess, favicon.ico, and other resources.
The below approach specializes the assets in the build environments you want production/development.
environments
angular.json// ...
"production": {
"index": {
"input": "src/environments/prod/index.html",
"output": "index.html"
},
"assets": [
// assets that must be included in all cases (common stuff)
"src/sitemap.xml",
"src/robots.txt",
"src/assets",
{
// mapping the root folder to /, for all files
"input": "src/environments/prod/root",
"output": "/",
"glob": "*"
}
],
"fileReplacements": [
// DOES NOT WORK HERE
],
// ...
},
// similarly for development
"development": {
"index": {
"input": "src/environments/dev/index.html",
"output": "index.html"
},
"assets": [
"src/sitemap.xml",
"src/robots.txt",
"src/assets",
{
"input": "src/environments/dev/root",
"output": "/",
"glob": "*"
}
],
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With