DartSass (dart_sass v0.8.0)

Copy Markdown View Source

DartSass is an installer and runner for Sass.

Profiles

You can define multiple configuration profiles. By default, there is a profile called :default which you can configure its args, current directory and environment:

config :dart_sass,
  version: "1.97.3",
  default: [
    args: ~w(css/app.scss ../priv/static/assets/app.css),
    cd: Path.expand("../assets", __DIR__)
  ]

Environment variables given as lists are joined with the PATH separator of the current operating system:

config :dart_sass,
  default: [
    args: ~w(css/app.scss ../priv/static/assets/app.css),
    cd: Path.expand("../assets", __DIR__),
    env: %{
      "SASS_PATH" => [Path.expand("../deps", __DIR__), Mix.Project.build_path()]
    }
  ]

Dart Sass configuration

There are three global configurations for the dart_sass application:

  • :version - the expected Sass version.

  • :version_check - whether to perform the version check or not. Useful when you manage the Sass executable with an external tool (eg. npm).

  • :path - the path to the Sass executable. By default it is automatically downloaded and placed inside the _build directory of your current app. Note that if your system architecture requires a separate Dart VM executable to run, then :path should be defined as a list of absolute paths.

Overriding the :path is not recommended, as we will automatically download and manage sass for you. But in case you can't download it (for example, the GitHub releases are behind a proxy), you may want to set the :path to a configurable system location.

For instance, you can install sass globally with npm:

$ npm install -g sass

Then the executable will be at:

NPM_ROOT/sass/sass.js

Where NPM_ROOT is the result of npm root -g.

Once you find the location of the executable, you can store it in a MIX_SASS_PATH environment variable, which you can then read in your configuration file:

config :dart_sass, path: System.get_env("MIX_SASS_PATH")

Note that overriding :path disables version checking.

Summary

Functions

Returns the path to the dart VM executable and to the sass executable.

Returns the version of the Sass executable.

Returns the configuration for the given profile.

Returns the configured Sass version.

Installs Sass with configured_version/0.

Installs, if not available, and then runs sass.

Runs the given command with args.

Functions

bin_paths()

Returns the path to the dart VM executable and to the sass executable.

bin_version()

Returns the version of the Sass executable.

Returns {:ok, version_string} on success or :error when the executable is not available.

config_for!(profile)

Returns the configuration for the given profile.

Returns nil if the profile does not exist.

configured_version()

Returns the configured Sass version.

install()

Installs Sass with configured_version/0.

If invoked concurrently, this task will perform concurrent installs.

install_and_run(profile, args)

Installs, if not available, and then runs sass.

This task may be invoked concurrently and it will avoid concurrent installs.

Returns the same as run/2.

run(profile, extra_args)

Runs the given command with args.

The given args will be appended to the configured args. The task output will be streamed directly to stdio. It returns the status of the underlying call.