[Bug] fileReplacements configuration can not replace html files
Versions
Angular CLI: 6.0.0
Node: 8.11.1
Angular: 6.0.0
Windows 7
Repro steps
Reproduce git: https://github.com/idododu/ng6-filereplacements-bug
- Step 1: add
fileReplacementsconfig inconfigurationsblock ofangular.json
"project-b": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.project-b.ts"
},
{
"replace": "src/app/home-a/home-a.component.html",
"with": "src/app/home-b/home-b.component.html"
},
{
"replace": "src/app/home-a/home-a.component.ts",
"with": "src/app/home-b/home-b.component.ts"
}
]
}
- Step 2:
npm run project-bto start dev server
Observed behavior
home-a.component.ts was replaced correctly.
home-a.component.tsin chrome source
home-a.component.tsin my source code
home-a.component.ts was not replaced
home-a.component.htmlin chrome source
module.exports = "<p>\r\n home-a works!\r\n</p>\r\n"
home-a.component.htmlin my source code
<p>
home-a works!
</p>
home-b.component.htmlin my source code
<p>
home-b works!
</p>
Desired behavior
- Expected to see
content of
home-a.component.htmlshould be replaced byhome-b.component.htmlsince i have configed inangular.json
{
"replace": "src/app/home-a/home-a.component.html",
"with": "src/app/home-b/home-b.component.html"
},
- Usecase
Suppose we got two projects: Project A and Project B.
They share the most of my source codes except HomeComponent.
And I would like to put the codes in the same repo, and build different projects through
environmentsconfiguration.
Mention any other details that might be useful (optional)
Another point: can we support glob expressions in fileReplacements configuration?
{
"replace": "src/app/home-a/*/**",
"with": "src/app/home-b/*/**"
}
Confirmed. This doesn't work for me either:
"fileReplacements": [
{
"replace": "src/app/app.component.html",
"with": "src/app/som-other.html"
}
]
However it still goes to look for the file, I noticed this because I misspelled 'some-other.html' and got the following error:
The src/app/some-other.html path in file replacements does not exist.
FYI, this has been addressed and will be part of the 6.1 release.
To look at that change, please refer to this PR: angular/devkit#887
Just for reference: https://github.com/angular/devkit/issues/885 explains:
Currently, the file replacement functionality works only for TS files. More specifically - it works only for files that are part of the webpack compiler host.
The above-mentioned https://github.com/angular/devkit/pull/887 apparently fixes that; can't wait for 6.1 now ;-)
(And indeed, for me .scss files are not copied either.)
scss files are indeed not copied. Also not working with 6.1.0-beta.2. Any idea if it will be?
~~FYI, not working in 6.1.0-rc.0 either~~ UPDATE: if updating an existing project it's not enough to update the global and project-local @angular/cli version, you also need to update the @angular-devkit/build-angular package to 0.7.0-rc.0. It is a separate package.
npm i -g @angular/[email protected]
cd your-project-folder
npm i -D @angular/[email protected] @angular-devkit/[email protected]
@robindijkhof
Issue still happening in this version: "@angular/cli": "6.1.5".
Issue still happening in this version: "@angular/cli": "6.1.5".
"configurations": { "production": { "optimization": true, "outputHashing": "all", "sourceMap": false, "extractCss": true, "namedChunks": false, "aot": true, "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true, "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ] } }
UPDATE:
fixed by updating @angular-devkit/build-angular as @suau suggested Thanks @suau
@luillyfee @georgefam did you make sure you've updated @angular-devkit/build-angular as well ?
@suau I can no longer reproduce this issue. Also I cannot remember how I did make it work, maybe is how you are pointing out.
Any updates on this issue? Should it be fixed in 6.1.5?
Im trying to replace a constants.scss (with constants.newconfig.scss) file that I import at the top of my root styles file. But none of the newconfig styles are pulling through.
The strange thing is if I use this method with a component specific scss file it works perfectly. From what I can see its only with the root style files.
Here's a stackoverflow link to my question.
Im using 6.1.5
@developcodeza-matthew there is not link in your answer!
@luillyfe My bad 🙈 Should be there now
I'm facing the same issue with CLI 6.2.2
UPDATE:
I fixed it by updating @angular-devkit/build-angular as @suau suggested
@iki789 You save my life . Thanks Bro.
Is it possible to do dynamic file replacements?
I'm trying to build two different UI's from the same App. So i have two different html files.
"fileReplacements": [
{
"replace": "**.template1.ts",
"with": "**.template2.ts"
}
It's throwing me an error. Is this possible?
using angular ^6.0.9 & angular/cli ^6.0.8, updated @angular-devkit/build-angular in devDependencies in package.json to ^0.8.9. seems to work as expected with environments and all
with @angular/cli 7.3.0 html files are not replaced.
Replacing html files is good feature to have. Very strange that the angular team hasn't addressed this issue.
Has anyone got a fix for this yet?
UPDATE: if updating an existing project it's not enough to update the global and project-local @angular/cli version, you also need to update the @angular-devkit/build-angular package to 0.7.0-rc.0. It is a separate package.
npm i -g @angular/[email protected] cd your-project-folder npm i -D @angular/[email protected] @angular-devkit/[email protected]@robindijkhof
@AntonisFK @MattCMcNabb did you make sure yo update to the newest version as well ? works fine for me.