The reference implementation of Sass, written in Dart.

Overview

A Dart implementation of Sass. Sass makes CSS fun again.

Sass logo npm statistics Pub version
GitHub actions build status
@SassCSS on Twitter
stackoverflow
Gitter

Using Dart Sass

There are a few different ways to install and run Dart Sass, depending on your environment and your needs.

From Chocolatey or Scoop (Windows)

If you use the Chocolatey package manager or the Scoop package manager for Windows, you can install Dart Sass by running

choco install sass

or

scoop install sass

That'll give you a sass executable on your command line that will run Dart Sass. See the CLI docs for details.

From Homebrew (macOS)

If you use the Homebrew package manager for macOS, you can install Dart Sass by running

brew install sass/sass/sass

That'll give you a sass executable on your command line that will run Dart Sass.

Standalone

You can download the standalone Dart Sass archive for your operating system—containing the Dart VM and the snapshot of the executable—from the GitHub release page. Extract it, add the directory to your path, restart your terminal, and the sass executable is ready to run!

From npm

Dart Sass is available, compiled to JavaScript, as an npm package. You can install it globally using npm install -g sass which will provide access to the sass executable. You can also add it to your project using npm install --save-dev sass. This provides the executable as well as a library:

var sass = require('sass');

sass.render({file: scss_filename}, function(err, result) { /* ... */ });

// OR

var result = sass.renderSync({file: scss_filename});

See below for details on Dart Sass's JavaScript API.

From Pub

If you're a Dart user, you can install Dart Sass globally using pub global activate sass, which will provide a sass executable. You can also add it to your pubspec and use it as a library. We strongly recommend importing it with the prefix sass:

import 'package:sass/sass.dart' as sass;

void main(List<String> args) {
  print(sass.compile(args.first));
}

See the Dart API docs for details.

sass_api Package

Dart users also have access to more in-depth APIs via the sass_api package. This provides access to the Sass AST and APIs for resolving Sass loads without running a full compilation. It's separated out into its own package so that it can increase its version number independently of the main sass package.

From Source

Assuming you've already checked out this repository:

  1. Install Dart. If you download an archive manually rather than using an installer, make sure the SDK's bin directory is on your PATH.

  2. In this repository, run pub get. This will install Dart Sass's dependencies.

  3. Run dart bin/sass.dart path/to/file.scss.

That's it!

JavaScript API

When installed via npm, Dart Sass supports a JavaScript API that's fully compatible with Node Sass (with a few exceptions listed below), with support for both the render() and renderSync() functions. See the Sass website for full API documentation!

Note however that renderSync() is more than twice as fast as render() due to the overhead of asynchronous callbacks. Both render() and renderSync() support the following options:

No support is intended for the following options:

  • precision. Dart Sass defaults to a sufficiently high precision for all existing browsers, and making this customizable would make the code substantially less efficient.

  • sourceComments. Source maps are the recommended way of locating the origin of generated selectors.

Why Dart?

Dart Sass has replaced Ruby Sass as the canonical implementation of the Sass language. We chose Dart because it presented a number of advantages:

  • It's fast. The Dart VM is highly optimized, and getting faster all the time (for the latest performance numbers, see perf.md). It's much faster than Ruby, and close to par with C++.

  • It's portable. The Dart VM has no external dependencies and can compile applications into standalone snapshot files, so we can distribute Dart Sass as only three files (the VM, the snapshot, and a wrapper script). Dart can also be compiled to JavaScript, which makes it easy to distribute Sass through npm, which the majority of our users use already.

  • It's easy to write. Dart is a higher-level language than C++, which means it doesn't require lots of hassle with memory management and build systems. It's also statically typed, which makes it easier to confidently make large refactors than with Ruby.

  • It's friendlier to contributors. Dart is substantially easier to learn than Ruby, and many Sass users in Google in particular are already familiar with it. More contributors translates to faster, more consistent development.

Compatibility Policy

For the most part, Dart Sass follows semantic versioning. We consider all of the following to be part of the versioned API:

  • The Sass language semantics implemented by Dart Sass.
  • The Dart API.
  • The JavaScript API.
  • The command-line interface.

Because Dart Sass has a single version that's shared across the Dart, JavaScript, and standalone distributions, this may mean that we increment the major version number when there are in fact no breaking changes for one or more distributions. However, we will attempt to limit the number of breaking changes we make and group them in as few releases as possible to minimize churn. We strongly encourage users to use the changelog for a full understanding of all the changes in each release.

There is one exception where breaking changes may be made outside of a major version revision. It is occasionally the case that CSS adds a feature that's incompatible with existing Sass syntax in some way. Because Sass is committed to full CSS compatibility, we occasionally need to break compatibility with old Sass code in order to remain compatible with CSS.

In these cases, we will first release a version of Sass that emits deprecation warnings for any stylesheets whose behavior will change. Then, at least three months after the release of a version with these deprecation warnings, we will release a minor version with the breaking change to the Sass language semantics.

Browser Compatibility

In general, we consider any change to Dart Sass's CSS output that would cause that CSS to stop working in a real browser to be a breaking change. However, there are some cases where such a change would have substantial benefits and would only negatively affect a small minority of rarely-used browsers. We don't want to have to block such a change on a major version release.

As such, if a change would break compatibility with less than 2% of the global market share of browser according to StatCounter GlobalStats, we may release a minor version of Dart Sass with that change.

Node.js Compatibility

We consider dropping support for a given version of Node.js to be a breaking change as long as that version is still supported by Node.js. This means that releases listed as Current, Active LTS, or Maintenance LTS according to the Node.js release page. Once a Node.js version is out of LTS, Dart Sass considers itself free to break support if necessary.

Behavioral Differences from Ruby Sass

There are a few intentional behavioral differences between Dart Sass and Ruby Sass. These are generally places where Ruby Sass has an undesired behavior, and it's substantially easier to implement the correct behavior than it would be to implement compatible behavior. These should all have tracking bugs against Ruby Sass to update the reference behavior.

  1. @extend only accepts simple selectors, as does the second argument of selector-extend(). See issue 1599.

  2. Subject selectors are not supported. See issue 1126.

  3. Pseudo selector arguments are parsed as <declaration-value>s rather than having a more limited custom parsing. See issue 2120.

  4. The numeric precision is set to 10. See issue 1122.

  5. The indented syntax parser is more flexible: it doesn't require consistent indentation across the whole document. See issue 2176.

  6. Colors do not support channel-by-channel arithmetic. See issue 2144.

  7. Unitless numbers aren't == to unit numbers with the same value. In addition, map keys follow the same logic as ==-equality. See issue 1496.

  8. rgba() and hsla() alpha values with percentage units are interpreted as percentages. Other units are forbidden. See issue 1525.

  9. Too many variable arguments passed to a function is an error. See issue 1408.

  10. Allow @extend to reach outside a media query if there's an identical @extend defined outside that query. This isn't tracked explicitly, because it'll be irrelevant when issue 1050 is fixed.

  11. Some selector pseudos containing placeholder selectors will be compiled where they wouldn't be in Ruby Sass. This better matches the semantics of the selectors in question, and is more efficient. See issue 2228.

  12. The old-style :property value syntax is not supported in the indented syntax. See issue 2245.

  13. The reference combinator is not supported. See issue 303.

  14. Universal selector unification is symmetrical. See issue 2247.

  15. @extend doesn't produce an error if it matches but fails to unify. See issue 2250.

  16. Dart Sass currently only supports UTF-8 documents. We'd like to support more, but Dart currently doesn't support them. See dart-lang/sdk#11744, for example.

Disclaimer: this is not an official Google product.

Comments
  • --watch is flaky

    --watch is flaky

    Hi,

    I got a new Mac recently so I thought I would use this as a reason to move from Ruby Sass to Dart Sass.

    The installation was all OK and it works in my projects, but I'm having an issue where after a certain number of SCSS changes (circa 20 or so) Sass stops working.

    The work around I have is just stopping the watch (ctrl + c) restarting it and then making a change to the file so it compiles.

    I never had this problem on Ruby Sass, so I wiped and re-installed Dart Sass, but it's still happening.

    I do have my editor (VS Code) set to auto-save, but as mentioned above the issue wasn't happening with Ruby Sass and I used auto-save in that version as well.

    Has anyone else had this issue / and or know how to fix it, instead of constantly having to stop the watch and re-compile?

    Many thanks

    bug CLI 
    opened by EmilyChews 31
  • HTML entities are replaced with the actual symbols in the compiled css

    HTML entities are replaced with the actual symbols in the compiled css

    🐛 bug report

    HTML entities are replaced with the actual symbols in the compiled css. And thus, the symbols show up garbled.

    For example: If I comple scss with a pseudo element with html entity like this:

    Source SCSS:

    @charset "UTF-8";
    #test:before { content: "\2713"; }
    

    Compiled css:

    @charset "UTF-8";
    #test:before {
      content: "✓";
    }
    

    The html entity '\2713' is replaced with the actual symbol '✓' in the complied css, and then, it's shown like this "e✓" on browsers.

    needs info 
    opened by mtskf 26
  • Add a --quiet-upstream flag

    Add a --quiet-upstream flag

    Most users only have the capacity to fix deprecation warnings in their own code, but they may end up using libraries that have their own deprecation warnings. We should add a --quiet-upstream flag (and similar flags for the Dart and JS APIs) to silence deprecation warnings emitted by upstream libraries (that is, libraries loaded through load paths and package: URLs).

    I think this flag should probably not silence warnings due to @warn, since libraries frequently use those to indicate that downstream users are using the library in an invalid or deprecated way.

    enhancement CLI 
    opened by nex3 26
  • Pre-Built Binaries for Apple Silicon?

    Pre-Built Binaries for Apple Silicon?

    Apologies if this has been asked; I did search!

    With the first Apple Silicon Macs about 30-45 days out, is there a plan to make the Mac pre-built downloads Universal binaries? I understand that I can try building Dart Sass on my own to support Apple Silicon, but I'd rather leave it to the experts if you're going to continue releasing pre-built binaries that support the Mac platform. Thanks!

    enhancement CLI 
    opened by bdkjones 25
  • Add an embeddable execution mode

    Add an embeddable execution mode

    It's desirable to be able to use Dart Sass from various different language environments, with functions and importers defined in the host language, while still getting the language semantics of Dart Sass and the performance of the Dart VM. We could theoretically expose the VM plus Dart Sass as a C API, but figuring out how to get that to build reliably (let alone efficiently) seems like a nightmare.

    A much easier solution would be to create an executable that uses stdin/stdout to allow a caller to define functions and importers. This would require defining a protocol of some sort—probably either JSON- or protobuf-based—for communication and for serializing Sass values.

    This should probably be in a separate package from Dart Sass proper, but that package doesn't exist yet so I'm filing this here for now.

    enhancement 
    opened by nex3 22
  • JS API: Support custom importers

    JS API: Support custom importers

    We need to support the node-sass API's importer option, which specifies custom importers that locate and load source files. Note that this may require the use of something like synchronize.js, since Dart Sass is entirely synchronous.

    enhancement JavaScript 
    opened by nex3 22
  • Issue with @extend, placeholders and @use

    Issue with @extend, placeholders and @use

    We're refactoring a large codebase from @import to @use and I noticed some strange errors with placeholders and placeholders extending placeholders. To illustrate the behaviour, I created a simplified repo:

    https://github.com/tuelsch/sass-playground

    The interesting file is src/placeholders.scss. As it is, the build fails (with npm start, the first build does not print the error to the console, but rather the out.css at root). But as soon as you comment out the %whatever placeholder, the build succeeds. What's even stranger, if you just move the declaration above the %placeholder declaration, the build succeeds as well.

    I don't get it. Is this a bug with sass or am I not supposed to use %placeholders in this specific way?

    needs info 
    opened by gfellerph 21
  • Error compiling bootstrap glyphicon, and font-awesome.

    Error compiling bootstrap glyphicon, and font-awesome.

    I am trying to compile bootstrap-sass or font-awesome-sass to normal css. The fonts are being added correctly however the '::after -> content ' attribute is messaged up completely.

    To check that its not on my end, I took the content of a working icon, and pasted it instead of the content that your compiler produced and it works fine.

    needs info 
    opened by yanivkalfa 20
  • Implement Index and a default file if directory given in import

    Implement Index and a default file if directory given in import

    Ref to: https://github.com/sass/sass/pull/2456

    I've not done Dart before so any help will be accepted.

    • [x] Signed Contributors (waiting for legal to approve)
    • [x] Rebase and remove extra commits

    See sass/sass-spec#1206

    opened by john681611 19
  • 1.23.0-module.beta.1 was mistakenly released under the `latest` dist-tag

    1.23.0-module.beta.1 was mistakenly released under the `latest` dist-tag

    ζ npm view [email protected] version
    1.23.0-module.beta.1
    

    If users install dart sass via npm install sass and use it along with sass-loader, sass-loader's version check will fail. https://github.com/webpack-contrib/sass-loader/blob/aa9b53b4d1c14117c4ca114a13cecb6e53b4e87a/src/getSassImplementation.js#L28-L31

    infrastructure 
    opened by sodatea 18
  • Problem since 1.40.0 with bootstrap 5

    Problem since 1.40.0 with bootstrap 5

    Hello,

    The following code of bootstrap produce a build error since sass 1.40.0 (https://github.com/twbs/bootstrap/blob/main/scss/mixins/_grid.scss)

    margin-top: calc(var(--#{$variable-prefix}gutter-y) * -1); // stylelint-disable-line function-disallowed-list
    margin-right: calc(var(--#{$variable-prefix}gutter-x) * -.5); // stylelint-disable-line function-disallowed-list
    margin-left: calc(var(--#{$variable-prefix}gutter-x) * -.5); // stylelint-disable-line function-disallowed-list
    

    If I remove the minus sign before 1 or .5 it works. I'm not sure that multiplication should failed because of a minus sign.

    bug needs info 
    opened by kris2kris 17
  • Issue with Deprecated Division warning in SASS

    Issue with Deprecated Division warning in SASS

    I am doing a large project converting old SASS code (specifically node-sass), into newer SASS using the SASS npm package (v1.56.1), and I am getting this error message

    DEPRECATION WARNING: Using / for division is deprecated and will be removed in Dart Sass 2.0.0. Recommendation: math.div(3, 4)
    

    It picks on this line of code, and I don't use Dart-Sass either... $_this: nth($short, $_i);

    I am finding this confusing as I am not trying to divide the numbers, and the aren't separated by a /, can someone explain please, or at least help me with a solution, as ignoring the line isn't working either?

    If it helps anyone, I have included the whole statement now...

    @function parse-span(
      $short,
      $key: span
    ) {
      $_return: ();
    
      @if type-of($short) == map {
        $_return: $short;
      } @else {
        $_at: index($short, at);
    
        @if $_at {
          $_loci: $_at + 1;
          $_location: nth($short, $_loci);
          $_return: map-merge($_return, (location: $_location));
          $short: set-nth($short, $_at, null);
          $short: set-nth($short, $_loci, null);
        }
    
        $_i: 1;
        $_span: ();
    
        @while $_i <= length($short) {
          $_this: nth($short, $_i); <--- faulty line?
    
          @if type-of($_this) == number {
            $_span: append($_span, $_this);
            $short: set-nth($short, $_i, null);
          } @else if $_this == of {
            $short: set-nth($short, $_i, null);
            $_i: length($short) + 1;
          }
    
          $_i: $_i + 1;
        }
    
        @if length($_span) > 0 {
          $_span: if(length($_span) == 1, nth($_span, 1), $_span);
          $_return: map-merge($_return, ($key: $_span));
        }
    
        $_return: map-merge($_return, parse-grid($short));
      }
    
      @return $_return;
    }
    
    $_gutters: parse-span($short, gutter-override);
    

    Here is an image of the actual warning 6a5YQ

    The Migrator doesn't pick up any changes that need to be made in any of my code, in relation to this :/ Any help would be greatly appreciated :)

    opened by takuhii 0
  • How to lint/check set of sass files without compile it?

    How to lint/check set of sass files without compile it?

    Hi, in my projects i use Sass with SCSS syntax.

    I want to use something like tsc --noEmit which is essentially a TypeScript file validity check and it returns a code other than 0 if there are static analysis errors.

    Is there any way to use Sass CLI in a similar way for static analysis?

    Tools like stylelint don't quite fit, as they are more for checking the code style.

    opened by krutoo 0
  • Add --fatal-deprecations and --future-deprecations

    Add --fatal-deprecations and --future-deprecations

    Partial fix for #633 and #1363.

    Still need to do:

    • [ ] Tests for both the CLI and the Dart API
    • [ ] JS API (would it make sense to add this separately to keep the JS API update process from blocking the CLI?)
    opened by jathak 0
  • Sass watcher doesn't re-compile on changes to meta.load-css() loaded modules?

    Sass watcher doesn't re-compile on changes to meta.load-css() loaded modules?

    (I'm using v1.55.0)

    In order to use CSS @layer efficiently on an existing code-base, I switched from e.g.:

    /* screen.scss */
    @use 'default';
    @use 'layout';
    @use 'theme';
    

    to:

    /* screen.scss */
    @use 'sass:meta';
    
    @layer default { @include meta.load-css('default'); }
    @layer layout { @include meta.load-css('layout'); }
    @layer theme { @include meta.load-css('theme'); }
    

    That's by far the simplest upgrade path, rather than wrapping each module individually with a layer or mixin.

    But since making that change, the watcher no longer compiles any changes to modules other than screen.scss itself. Changes to any of the loaded modules are ignored by the watcher. I don't see anything about that in the docs, or the specs, or any other issues mentioning it - but I was able to reproduce the problem consistently.

    Is that the expected behavior? Are others able to reproduce this?

    enhancement 
    opened by mirisuzanne 4
Releases(1.56.1)
A reference credential wallet built on Flutter and DIDKit.

Check out the Credible documentation here. Credible Credible is a native mobile wallet that supports W3C Verifiable Credentials and Decentralized Iden

Spruce Systems, Inc. 31 Nov 7, 2022
A reference app in flutter using the BLoC pattern.

flutter_dice A sample Flutter app that shows how to manage responsive state using the provider pattern. Concepts Illustrated Provider pattern Using a

CodeGrue 74 Nov 18, 2022
An address search field which helps to autocomplete an address by a reference

Address Search Field Widget builders to create 'address search widgets' which helps to autocomplete an address using a reference. They can be used to

Jose Luna 13 Aug 14, 2022
Get It - Simple direct Service Locator that allows to decouple the interface from a concrete implementation and to access the concrete implementation from everywhere in your App. Maintainer: @escamoteur

❤️ Sponsor get_it This is a simple Service Locator for Dart and Flutter projects with some additional goodies highly inspired by Splat. It can be used

Flutter Community 1k Nov 21, 2022
Mysql.dart - MySQL client for Dart written in Dart

Native MySQL client written in Dart for Dart See example directory for examples

null 43 Oct 10, 2022
Socketio dart server and client - Full Socket.io implementation using Dart Lang

Getting Started Step 1: Run dart_server.dart Step 2: Android Emulator has proble

Trần Thiên Trọng 1 Jan 23, 2022
A build system for Dart written in Dart

These packages provide libraries for generating, compiling and serving Dart code. Getting started with build_runner General FAQ Windows FAQ FAQ for Bu

Dart 668 Nov 17, 2022
A dart implementation of fixed precision numbers.

The Fixed package allows you to store and perform maths on numbers with a fixed scale (fixed no. of decimal places). All amounts are store as integers

Brett Sutton 6 Jun 4, 2022
The Dart language implementation of gRPC.

The Dart implementation of gRPC: A high performance, open source, general RPC framework that puts mobile and HTTP/2 first. Learn more Quick Start - ge

grpc 724 Nov 27, 2022
A simple dart zeromq implementation/wrapper around the libzmq C++ library

dartzmq A simple dart zeromq implementation/wrapper around the libzmq C++ library Features Currently supported: Creating sockets (pair, pub, sub, req,

Moritz Wirger 17 Nov 2, 2022
Firebase dart common interface and implementation for Browser, VM, node and flutter

firebase.dart Firebase dart common interface and implementation for Browser, VM, node and flutter Firebase Initialization Usage in browser import 'pac

Tekartik 6 Nov 28, 2021
A web-safe implementation of dart.io.Platforms. Helps avoid the "Unsupported operation: Platform._operatingSystem" runtime error.

Universal Platform - A Web-safe Platform class Currently, if you include the dart.io.Platform anywhere in your code, your app will throw the following

gskinner team 86 Nov 20, 2022
A dart implementation of the chord.js javascript package to display beautiful chord diagrams

flutter_guitar_tabs This is a dart implementation of the chord.js javascript package to display beautiful chord diagrams like the ones below. Where to

null 20 Nov 16, 2022
Flutter plugin that provides a quick&dirty workaround for incompatibility between VMWare Airwatch MDM solution and Dart Sockets implementation

airwatch_socket_workaround This plugin has been created to enable flutter apps to reach endpoints that are only reachable using a VMWare airwatch per

Gonçalo Silva 5 Nov 11, 2022
ESP-Touch Dart API for Flutter. Platform-specific implementation for Android (Java) and iOS (Objective-C).

esptouch_flutter Flutter plugin for ESP-Touch to configure network for ESP-8266 and ESP-32 devices. Runs on iOS and Android. esptouch_flutter is Flutt

SMAHO Engineering OSS 84 Nov 13, 2022
Implementation of data structures and algorithms in Dart programming language.

Algorithms in Dart Implementation of several algorithms with Dart programming language. Use dartdoc to generate documentation. Lists List data structu

Mafinar Khan 195 Oct 23, 2022
Lite-graphql - A light way implementation of GraphQL client in dart language

lite GraphQL client A light way implementation of GraphQL client in dart languag

Vincenzo Palazzo 3 Mar 17, 2022
Dart Implementation of the ISO-8583 banking protocol.

Dart Implementation of the ISO-8583 banking protocol. Supports 03xx message class (File Actions Message - 1987) and is compatible with most PoS device

Mahdi K. Fard 12 May 26, 2022
A simple and efficient FFT implementation for Dart

fftea A simple and efficient Fast Fourier Transform (FFT) library. FFT converts a time domain signal to the frequency domain, and back again. This is

Liam Appelbe 29 Nov 18, 2022