7

I’m working with Dart 2 and AngularDart 5.

⚠ I searched online about my question, but I didn’t find a satisfactory answer.

❔ Can somebody explain all the steps I need to include and to work with SCSS style files within my AngularDart application?

I started with quickstart application that you can find here.

Thank you!

Marco
  • 593
  • 8
  • 23

3 Answers3

18
  1. Add a dev dependency to your pubspec.yaml for sass_builder: ^2.0.0.
  2. Run pub get to download the new dependencies.
  3. Create a sass file ex: lib/app_component.scss and add some styles to it.
  4. Add a the compiled css stylesheet to your the @Component annotation in lib/app_component.dart: styleUrls: const ['app_component.css'],

The css file will be generated by sass_builder during the build process.

nshahan
  • 426
  • 3
  • 4
6

If you are using angluar_components. One could simply turn it on:

  1. Create a build.yaml file with the following content :

    targets:
      $default:
        builders:
          angular_components|scss_builder:
            enabled: True
    
  2. Use the following convention for the styleUrl annotations: styleUrls: const ['app_component.scss.css']
  3. Write your sass in the *.scss files.
Serverplumber
  • 59
  • 1
  • 3
  • 4
    Technically sass_builder isn't included in the build tool. It is a dependency of angular_components. This technique does work, but you are relying on the sass_builder package as a transitive dependency through the angular_components package. If you stop using angular_components or never were to begin with then this will not work. – nshahan Feb 13 '19 at 17:32
1

With newest versions:

  1. Surprise: In styleUrls are in a different CSS filename (not with the .scss.css extension, just .css; e.g. app_component.css, but the styles are in app_component.scss).

  2. Surprise: In app_component.scss, import without lib in the path:

@import 'package:angular_components/app_layout/mixins';
  1. I am using this command:
pub run build_runner serve --verbose

See with package info: https://github.com/dart-lang/angular_components/issues/374#issuecomment-636344237

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77