rules_sass icon indicating copy to clipboard operation
rules_sass copied to clipboard

Add example of how to import from Angular Material's SASS stylesheets

Open achew22 opened this issue 6 years ago • 20 comments

🚀 feature request

It would be nice if the example's styles.css showed how to import something like

@import '~@angular/material/theming';

https://material.angular.io/guide/theming-your-components

Relevant Rules

This may be better as a rules_sass feature request.

Describe alternatives you've considered

I couldn't figure out how to depend on the material scss files, so I just vendored them and made a sass_library myself.

achew22 avatar Sep 20 '19 05:09 achew22

This is the approach I took:

BUILD

sass_library(
    name = "angular_material_theming",
    srcs = [
        "@npm//:node_modules/@angular/material/_theming.scss",
    ]
)

sass_binary(
    name = "global_app_styles",
    src = "styles.scss",
    deps = [
        ":app_theme",
        ":angular_material_theming",
        "//some/other/sass/theme/library",
    ]
)

styles.scss

@import 'external/npm/node_modules/@angular/material/theming';

//...

The editor doesn't understand the import and flags it as an issue however

mattem avatar Sep 23 '19 15:09 mattem

/cc @jelbourn yeah I think this is a rules_sass thing. I'll transfer the issue

alexeagle avatar Sep 23 '19 15:09 alexeagle

@alexeagle @jelbourn What's the current recommended way to do this?

nex3 avatar Sep 23 '19 16:09 nex3

I actually don't know myself- @alexeagle should we be putting a BUILD file in our npm release?

jelbourn avatar Sep 24 '19 00:09 jelbourn

Running into this myself. Any new information or workaround?

@achew22 Can you share this vendored solution you made?

timwright35 avatar Sep 26 '19 17:09 timwright35

I don't think material should publish a BUILD file because you'd want any sass library to work with Bazel.

How would this work with sass outside of Bazel? I think we should make it the same.

alexeagle avatar Sep 26 '19 18:09 alexeagle

We just put a Sass file in the root of our package. With webpack you would just import with the tilde convention

@import '~@angular/material/theming';

Should each application need to define their own sass_library for that file?

jelbourn avatar Sep 26 '19 18:09 jelbourn

seems like maybe you want to port that tilde feature from the webpack sass loader into sass proper? then you'd look through the third-party installed packages to resolve that.

At this point people have written enough webpack-specific code that we have to treat it as standard syntax in order to interop with existing codebases I guess?

alexeagle avatar Sep 26 '19 18:09 alexeagle

@mattem couldn't get this to work.

timwright35 avatar Sep 26 '19 19:09 timwright35

We're discussing plans for a portable package import scheme in https://github.com/sass/sass/issues/2739. We probably won't end up using the same syntax as Webpack, but it should eventually solve this issue.

nex3 avatar Sep 27 '19 09:09 nex3

I think it's unfair that you should be forced to adopt someone else's syntax, but if you don't use the same syntax as Webpack we need some plan to migrate everyone's code right?

alexeagle avatar Sep 27 '19 14:09 alexeagle

That's true, but the semantics are different enough anyway (e.g. the built-in importer won't support package.json-defined entrypoints) that that's probably a less painful migration than just co-opting the webpack syntax would be.

nex3 avatar Sep 27 '19 15:09 nex3

If the migration is painful then we'll still have webpack sass imports indefinitely and we'll end up having to support them under Bazel too (I suppose maybe in a layer above rules_sass - Angular CLI can't tell all our users to do something painful when we introduce Bazel)

alexeagle avatar Sep 27 '19 15:09 alexeagle

I don't think migrating to pkg: will be particularly painful on the user's end, it'll just take time.

nex3 avatar Sep 27 '19 19:09 nex3

I agree that a migration from ~ to pkg: overall won't be painful, but during that migration period it is sometimes expected to support two build systems (in our case the old, Webpack based Angular CLI and the new, Bazel), so having some support for the ~ would definitely make things easier here.

Is there a recommended approach here? Attempted to use the output of a genrule as the src for sass_binary, but it let to other import issues.

mattem avatar Dec 10 '19 17:12 mattem

What is the currently recommended/best/correct approach to include external stylesheets?

jonsch318 avatar Jun 26 '20 16:06 jonsch318

I agree that a migration from ~ to pkg: overall won't be painful, but during that migration period it is sometimes expected to support two build systems (in our case the old, Webpack based Angular CLI and the new, Bazel), so having some support for the ~ would definitely make things easier here.

Is there a recommended approach here? Attempted to use the output of a genrule as the src for sass_binary, but it let to other import issues.

any progress on supporting the ~ imports? Would be nice to support something like ts_librarys module_name for the scss_library as well.

lukasholzer avatar Jul 06 '20 07:07 lukasholzer

any progress on this issue?

Phillip9587 avatar Jan 11 '21 17:01 Phillip9587

@Phillip9587 see https://github.com/bazelbuild/rules_sass/pull/122#pullrequestreview-507854016

lukasholzer avatar Jan 12 '21 16:01 lukasholzer

If I understand the readme of the webpack sass-loader correctly, ~ is deprecated. We added the include_paths option to the solution that @mattem provided and it works with both Bazel and ng build.

BUILD.bazel

sass_library(
    name = "angular_material_theming",
    srcs = [
        "@npm//:node_modules/@angular/material/_theming.scss",
    ]
)

sass_binary(
    name = "global_app_styles",
    src = "styles.scss",
    include_paths = ["external/npm/node_modules"],
    deps = [
        ":app_theme",
        ":angular_material_theming",
        "//some/other/sass/theme/library",
    ]
)

styles.scss

@import '@angular/material/theming';

//...

sessfeld avatar Feb 22 '21 18:02 sessfeld