-
Notifications
You must be signed in to change notification settings - Fork 19
Feature Request: One SCSS file for each component #72
Comments
Hi @wembernard
|
I'd like to have "one file per component" - each component having its own style. Currently, I'm already using your workaround with
is kinda cumbersome and requires you to edit this file everytime you rename/delete some .scss file. |
Well, there is no other way to do so... If you create a
|
In gulp-angular we had a mechanism for auto injecting sub scss files in the index. It was no so great, and caused ordering problems. Now, modern fmk have their way to include style on each component. So we're not going to reproduce auto injecting thing. Look at https://angular.io/docs/ts/latest/guide/component-styles.html instead. |
@Swiip I know and I loved it 👍 I fixed ordering problems by prefixing files with About |
Ok, I found how to make this work. Here is an example: @Component({
selector: 'home',
template: require('./home.component.html'),
styles: [ String(require('./home.component.scss')) ]
}) Interesting notes:
If you agree with this solution, I suggest to add this example in your generator :) |
Perfect, that was what I got in mind ! +1 for keeping this as an example |
Reopened to keep example |
The suggested solution is causing the the ecapsulation to drop. I removed "style" from the css loader and replaced it with css-to-string(-loader). Now I can use |
if you want to load both, change the index.scss file to index.global.scss then use the following:
Afterwards, the index.global.scss file will load globally (I assume that's what's going on anyway) and the other scss files loaded in your modules will have encapsulation. |
I'm using an additional require expression for webpack, it is working, even if I think is not most elegant solution. The goal was to keep Angular2 syntax as clean as possible, ie not using require inside component:
but rather this way:
Webpack is working fine this way. Maybe someone is having a better solution? |
Description
As a best practice, I would love to be able to have one SCSS file per component such as
Is it on your roadmap?
The text was updated successfully, but these errors were encountered: