-
Notifications
You must be signed in to change notification settings - Fork 12k
fileReplacements doesn't work with css files #11451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As said in #10881 (comment), ng-cli should be able to replace all type of files from 6.1.0, and not only |
We added the generic replacement functionality in angular/devkit#887, but this is limited to webpack loader and plugins that actually use the webpack file system. This might not work for all files, and we should error out when we know that's the case. |
I have updated my angular/cli to version 6.1.1 and angular-devkit/build-angular to version 0.7.1.
|
So I have updated angular/cli to version 6.1.2 but to no avail. |
@angular/[email protected] OR @angular/[email protected] Replacing scss files still not working. |
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 |
with @angular/cli: 6.2.1 I was able to switch the global style file, but not a variables file like this:
However the latter would be a more lean solution. |
I am writing an app that is built for several clients. |
@shprink My exact need as well. Holding my thumbs that these issues will be solved soon so we can use fileReplacements as you would with Android Build Flavors or Swifts Build Variants |
@shprink same 👍 I created component "widget" and need some static demo for this component. It mean, that I need to change controller, but html and styles stay same. To do it I can use "fileReplacement" feature. But it doesn't work... src/app/widget/widget.component.ts: import {Component, OnInit} from '@angular/core';
@Component({
selector: 'fh-widget',
templateUrl: './widget.component.html',
styleUrls: ['./widget.component.scss']
})
export class WidgetComponent implements OnInit {
title = '';
constructor() {
}
ngOnInit() {
this.title = 'wodget - real component';
}
} src/app/widget/widget-static/widget.component.ts import {Component, OnInit} from '@angular/core';
@Component({
selector: 'fh-widget',
templateUrl: './widget.component.html',
styleUrls: ['./widget.component.scss']
})
export class WidgetComponent implements OnInit {
title = '';
constructor() {
}
ngOnInit() {
this.title = 'widget - static component';
}
} and create a custom configuration with: "fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
},
{
"replace": "src/app/widget/widget.component.ts",
"with": "src/app/widget/widget-static/widget.component.ts"
}
] But
NgModule has path until original component src/app/widget/widget.component.ts. if I remove html+styles, because I don't need, then
do I something wrong? |
We also needed different variable configurations for different customers. This is the workaround we used:
src/scss/_variables.scss @import '_product_configuration';
/** Other variables, e.g. using colour functions, etc. */
/** [...] */ src/scss/style.scss @import '_variables';
@import '_fonts';
/** Other imports, that use the variables, e.g. Bootstrap, Angular Material */
/** [...] */
/** Other styles */
/** [...] */ Excerpt from angular.json: "configurations": {
"classic": {
"stylePreprocessorOptions": {
"includePaths": ["src/scss/product_configurations/classic"]
},
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.classic.ts"
},
{
"replace": "src/index.html",
"with": "src/index.classic.html"
}
]
},
"special-customer": {
"stylePreprocessorOptions": {
"includePaths": ["src/scss/product_configurations/special-customer"]
},
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.special-customer.ts"
},
{
"replace": "src/index.html",
"with": "src/index.special-customer.html"
}
]
}
} |
@richardtreier thanks for sharing that, it is a working workaround ! |
Using angular 7.2 I'm able to replace html files but not for scss files. Is there any updates? |
Actually html files don't work for me with 7.3 |
I am also unable to replace html files with 7.1, using code in my angular.json which previously worked:
Results in a build that uses UPDATE: After trying to update packages in various manners, oddly enough, literally doing |
any news on this? Is this going to be implemented? @shprink did your solution work with angular 7.x? It didn't work for me ... |
Same problem in here with Angular 7.2.10 (2019-03-20) I'm using this workaround meanwhile: #11451 (comment) |
@jesussobrino I use a major class in my body and use the environment to exchange it in the view. This causes a lot more css code but works pretty well. This also allows changeable themes as a nice sideeffect. import { Component } from '@angular/core';
import {environment} from '../environments/environment';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
constructor() {
document.body.classList.add(environment.theme);
}
} |
@richardtreier 's workaround didn't work for me (Angular 7.2) but I managed to achieve similar results (I guess) by redefining the in "configurations": {
"my-theme": {
"styles": ["src/product_configurations/my-theme/styles.scss"]
},
} Then for instance in @import "../../styles"; // Still get the common styles first
body.my-theme { // my-theme-specific styling
@import "components"; // my-theme-specific components styling under product_configurations/my-theme
} |
@Javarome This is how I did it too. Thinking more about the topic, I came to the conclusion that working with css variables is the best you can do. There is a polyfill for IE9+. Using |
@konsultaner Yes this should be better for colors and other variables, but how can this help providing different CSS code per theme, beyond properties' values? |
@Javarome Thats definitly not working with variables.. Thats right. |
I also need this functionality. We have a white-labelled application that need specific I want to avoid having multiple projects/configurations/apps defined in the angular.json, because adding new brands would require a change to the base code each time. In our case, TeamCity and OctoDeploy would take care of the rest. |
I need this feature for the ability to build the app using a specific theme which I can pass using a parameter. |
Hi, I need this functionality for different theme of my application. |
Thank you @richardtreier for this very nice solution. Just implemented with angular-cli 7.3.9 and it works as advertised. My initial difficulties were due to my own errors; perhaps others who claim this doesn't work may wish to revisit. |
Here is my solution to this problem app2
|
Thanks @richardtreier your solution worked perfectly! Since I'm a bit new to Angular CLI I had a bit of trouble understanding what https://scotch.io/tutorials/angular-shortcut-to-importing-styles-files-in-components |
I am trying to replace with robots.txt , doesn't work as well . |
@karocksjoelee robots.txt should work. In angular.json:
and then apply the file replacements:
|
Still doesn't work in 2020 ! |
The functionality of fileReplacements block is not very sophisticated because it just replaces files. The main problem is that it doesn't affect the resolve process of imports, thus breaks for almost all files that have transitive relative imports. For example if you have the following structure
and you want to replace the test.component.ts with test-new.component.ts, it won't work because the file content just replaces the content of the original test.component.ts in the test folder. The build process then looks up the imports like templateUrl and styleUrls which cannot be resolved in that context. There may be a way to have a working folder structure to deal with such problems, but it's very cumbersome. Because we need such functionality I'm using webpack with a custom webpack-resolve plugin instead of angular-cli. For the moment it works fine when using JIT and a bit limited when using AOT. But with angular 9 and ivy, new issues arrived. The hassle is real. There really should be a more sophisticated "fileReplacement" option that deals with the correct resolvement and imports of replaced files. |
json files still does not work
|
@manoyanx |
@tmtron, actually, |
I agree, but in this case the json files |
The "assets": [
"src/config"
"..."
], They are part of the bundle only if you import them directly using the
Otherwise, you'll need something like this: #7506 (comment) More related info: #3855, #7506, #7704 P.S. @manoyanx, your comment and the discussion that followed is not related to the original issue, if the above linked issues don't help, you should create a new issue. |
@SchnWalter oh right - I missed the |
Its a very important feature, please do give a fix on this ASAP. On working with Internationalization it is very much essential thing. Also the component specific files should also be get replaced by this Angular config. I am i18n for Internationalization, but the issue is with the SCSS file replacement for Arabic layout. |
Hi asphub, for the Internationalization you can use the i18n built in mechanism provided by Angular ! |
@mcescalante It's been awhile since your post but for index files try using this instead of "fileReplacements":
|
This also will be useful and easier for robots.txt replacement for production. |
@filipesilva @alan-agius4 any update on this? |
@kodze I am already using i18n for Internationalization, but the issue is with the SCSS file replacement for the UI to switch Arabic layout. I am using SCSS variables to manage this |
… values fileReplacement is meant to replace compilation source files (JavaScript or TypeScript) with other compilation source files in the build. With this change we add validation to fail the build when the files have unsupported extensions. Closes #11451
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)Area
Versions
node --version: v9.4.0
npm --version: 5.6.0
macOS high sierra 10.13.5
Repro steps
1- In angular.json add a new configuration and try to replace a css file.
2- add a simple background style to header.local.css
3- import the header.css file into styles.scss
E.g.
The log given by the failure
none
Desired functionality
get the header.css
replaced by header.local.css
Mention any other details that might be useful
Tested with angular cli version 6.0.1 and angular cli version 6.1.0-beta.0
The text was updated successfully, but these errors were encountered: