sass-site/source/documentation/cli/dart-sass.html.md.erb

362 lines
11 KiB
Plaintext
Raw Normal View History

2018-10-26 01:46:08 +02:00
---
title: Dart Sass Command-Line Interface
---
## Usage
The Dart Sass executable can be invoked in one of two modes.
### One-to-One Mode
```
sass <input.scss> [output.css]
```
One-to-one mode compiles a single input file (`input.scss`) to a single output
location (`output.css`). If no output location is passed, the compiled CSS is
printed to the terminal.
The input file is parsed as [SCSS][] if its extension is `.scss`, as the
[indented syntax][] if its extension is `.sass`, or as [plain CSS][] if its
extension is `.css`. If it has no extension, it's parsed as SCSS by default.
This can be controlled with the [`--indented` flag][].
[SCSS]: ../syntax#scss
[indented syntax]: ../syntax#the-indented-syntax
[plain CSS]: ../at-rules/import#importing-css
[`--indented` flag]: #indented
The special string `-` can be passed in place of the input file to tell Sass to
read the input file from [standard input][]. Sass will default to parsing it as
SCSSS unless the [`--indented` flag][] is passed.
[standard input]: https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)
### Many-to-many Mode
```
sass <input.css>:<output.css> <input/>:<output/>...
```
Many-to-many mode compiles one or more input files to one or more output files.
The inputs are separated from the outputs with colons. It can also compile all
Sass files in a directory to CSS files with the same names in another directory.
```shellsession
# Compiles style.scss to style.css.
$ sass style.scss:style.css
# Compiles light.scss and dark.scss to light.css and dark.css.
$ sass light.scss:light.css dark.scss:dark.css
# Compiles all Sass files in themes/ to CSS files in public/css/.
$ sass themes:public/css
```
When compiling whole directories, Sass will ignore [partial files][] whose names
begin with `_`. You can use partials to separate out your stylesheets without
creating a bunch of unnecessary output files.
[partial files]: ../at-rules/import#partials
## Options
### Input and Output
These options control how Sass loads its input files and how it produces output
files.
#### `--stdin`
This flag is an alternative way of telling Sass that it should read its input
file from [standard input][]. When it's passed, no input file may be passed.
```shellsession
$ echo "h1 {font-size: 40px}" | sass --stdin h1.css
$ echo "h1 {font-size: 40px}" | sass --stdin
h1 {
font-size: 40px;
}
```
The `--stdin` flag may not be used with [many-to-many mode][].
[many-to-many mode]: #many-to-many-mode
#### `--indented`
This flag tells Sass to parse the input file as the [indented syntax][]. If it's
used in [many-to-many mode][], all input files are parsed as the indented
syntax, although files they [import][] will have their syntax determined as
usual. The inverse, `--no-indented`, can be used to force all input files to be
parsed as [SCSS][] instead.
[import]: ../at-rules/import
The `--indented` flag is mostly useful when the input file is coming from
[standard input][], so its syntax can't be automatically determined.
```shellsession
$ echo -e 'h1\n font-size: 40px' | sass --indented -
h1 {
font-size: 40px;
}
```
#### `--load-path`
This option (abbreviated `-I`) adds an additional [load path][] for Sass to look
for imports. It can be passed multiple times to provide multiple load paths.
Earlier load paths will take precedence over later ones.
[load path]: ../at-rules/import#load-paths
```shellsession
$ cat style.scss
sass
$ sass --load-path=node_modules/bootstrap/dist/css style.scss style.css
```
#### `--style`
This option (abbreviated `-s`) controls the output style of the resulting CSS.
Dart Sass supports two output styles:
* `expanded` (the default) writes each selector and declaration on its own line.
* `compressed` removes as many extra characters as possible, and writes the
entire stylesheet on a single line.
```shellsession
$ sass --style=expanded style.scss
h1 {
font-size: 40px;
}
$ sass --style=compressed style.scss
h1{font-size:40px}
```
#### `--update`
If the `--update` flag is passed, Sass will only compile stylesheets whose
dependencies have been modified more recently than the corresponding CSS file
was generated. It will also print status messages when updating stylesheets.
```shellsession
$ sass --update themes:public/css
Compiled themes/light.scss to public/css/light.css.
```
### Source Maps
Source maps are files that tell browsers or other tools that consume CSS how
that CSS corresponds to the Sass files from which it was generated. They make it
possible to see and even edit your Sass files in browsers. See instructions for
using source maps in [Chrome][] and [Firefox][].
[Chrome]: https://developers.google.com/web/tools/chrome-devtools/javascript/source-maps
[Firefox]: https://developer.mozilla.org/en-US/docs/Tools/Style_Editor#Source_map_support
Dart Sass generates source maps by default for every CSS file it emits.
#### `--no-source-map`
If the `--no-source-map` flag is passed, Sass won't generate any source maps. it
cannot be passed along with other source map options.
```shellsession
$ sass --no-source-map style.scss style.css
```
#### `--source-map-urls`
This option controls how the source maps that Sass generates link back to the
Sass files that contributed to the generated CSS. Dart Sass supports two types
of URLs:
* `relative` (the default) uses relative URLs from the location of the source
map file to the locations of the Sass source file.
* `absolute` uses the absolute [`file:` URLs][] of the Sass source files. Note
that absolute URLs will only work on the same computer that the CSS was
compiled.
[`file:` URLs]: https://en.wikipedia.org/wiki/File_URI_scheme
```shellsession
# Generates a URL like "../sass/style.scss".
$ sass --source-map-urls=relative sass/style.scss css/style.css
# Generates a URL like "file:///home/style-wiz/sassy-app/sass/style.scss".
$ sass --source-map-urls=absolute sass/style.scss css/style.css
```
#### `--embed-sources`
This flag tells Sass to embed the entire contents of the Sass files that
contributed to the generated CSS in the source map. This may produce very large
source maps, but it guarantees that the source will be available on any computer
no matter how the CSS is served.
```shellsession
$ sass --embed-sources sass/style.scss css.style.css
```
#### `--embed-source-map`
This flag tells Sass to embed the contents of the source map file in the
generated CSS, rather than creating a separate file and linking to it from the
CSS.
```shellsession
$ sass --embed-source-map sass/style.scss css.style.css
```
### Other Options
#### `--watch`
This flag acts like the [`--update` flag][], but after the first round
compilation is done Sass stays open and continues compiling stylesheets whenever
they or their dependencies change.
[`--update` flag]: #update
```shellsession
$ sass --watch themes:public/css
Compiled themes/light.scss to public/css/light.css.
# Then when you edit themes/dark.scss...
Compiled themes/dark.scss to public/css/dark.css.
```
#### `--poll`
This flag, which may only be passed along with `--watch`, tells Sass to manually
check for changes to the source files every so often instead of relying on the
operating system to notify it when something changes. This may be necessary if
you're editing Sass on a remote drive where the operating system's notification
system doesn't work.
```shellsession
$ sass --watch --poll themes:public/css
Compiled themes/light.scss to public/css/light.css.
# Then when you edit themes/dark.scss...
Compiled themes/dark.scss to public/css/dark.css.
```
#### `--stop-on-error`
This flag tells Sass to stop compiling immediately when an error is detected,
rather than trying to compile other Sass files that may not contain errors. It's
mostly useful in [many-to-many mode][].
```shellsession
$ sass --stop-on-error themes:public/css
Error: Expected expression.
h1 {font-face: }
^
themes/light.scss 42:16 root stylesheet
```
#### `--interactive`
This flag (abbreviated `-i`) tells Sass to run in interactive mode, where you
can write [SassScript expressions][] and see their results. Interactive mode
also supports [variables][].
[SassScript expressions]: ../syntax/structure#expressions
[variables]: ../variables
```shellsession
$ sass --interactive
>> 1px + 1in
97px
>> $map: ("width": 100px, "height": 70px)
("width": 100px, "height": 70px)
>> map-get($map, "width")
100px
```
#### `--color`
This flag (abbreviated `-c`) tells Sass to emit [terminal colors][], and the
inverse `--no-color` tells it not to emit colors. By default, it will emit
colors if it looks like it's being run on a terminal that supports them.
[terminal colors]: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
<pre><code>$ sass --color style.scss style.css
Error: Incompatible units em and px.
$width: <span style="color: red">15px + 2em</span>
<span style="color: red">^^^^^^^^^^</span>
style.scss 1:9 root stylesheet
$ sass --no-color style.scss style.css
Error: Incompatible units em and px.
$width: 15px + 2em
^^^^^^^^^^
style.scss 1:9 root stylesheet</code></pre>
#### `--quiet`
This flag (abbreviated `-q`) tells Sass not to emit any warnings when compiling.
By default, Sass emits warnings when deprecated features are used or when the
[`@warn` rule][] is encountered. It also silences the [`@debug` rule][].
[`@warn` rule]: ../at-rules/warn
[`@debug` rule]: ../at-rules/debug
```shellsession
$ sass --quiet style.scss style.css
```
#### `--trace`
This flag tells Sass to print the full Dart or JavaScript stack trace when an
error is encountered. It's used by the Sass team for debugging errors.
```shellsession
$ sass --trace style.scss style.css
Error: Expected expression.
h1 {font-face: }
^
themes/light.scss 42:16 root stylesheet
package:sass/src/visitor/evaluate.dart 1846:7 _EvaluateVisitor._addExceptionSpan
package:sass/src/visitor/evaluate.dart 1128:12 _EvaluateVisitor.visitBinaryOperationExpression
package:sass/src/ast/sass/expression/binary_operation.dart 39:15 BinaryOperationExpression.accept
package:sass/src/visitor/evaluate.dart 1097:25 _EvaluateVisitor.visitVariableDeclaration
package:sass/src/ast/sass/statement/variable_declaration.dart 50:15 VariableDeclaration.accept
package:sass/src/visitor/evaluate.dart 335:13 _EvaluateVisitor.visitStylesheet
package:sass/src/visitor/evaluate.dart 323:5 _EvaluateVisitor.run
package:sass/src/visitor/evaluate.dart 81:10 evaluate
package:sass/src/executable/compile_stylesheet.dart 59:9 compileStylesheet
package:sass/src/executable.dart 62:15 main
```
#### `--help`
This flag prints a summary of this documentation.
```shellsession
$ sass --help
Compile Sass to CSS.
Usage: sass <input.scss> [output.css]
sass <input.scss>:<output.css> <input/>:<output/>
...
```
#### `--version`
This flag prints the current version of Sass.
```shellsession
$ sass --version
<%= impl_version(:dart) %>
```