You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
8.4 KiB

4 years ago
  1. A pure JavaScript implementation of [Sass][sass]. **Sass makes CSS fun again**.
  2. <table>
  3. <tr>
  4. <td>
  5. <img width="118px" alt="Sass logo" src="https://rawgit.com/sass/sass-site/master/source/assets/img/logos/logo.svg" />
  6. </td>
  7. <td valign="middle">
  8. <a href="https://www.npmjs.com/package/sass"><img width="100%" alt="npm statistics" src="https://nodei.co/npm/sass.png?downloads=true"></a>
  9. </td>
  10. <td valign="middle">
  11. <a href="https://travis-ci.org/sass/dart-sass"><img alt="Travis build status" src="https://api.travis-ci.org/sass/dart-sass.svg?branch=master"></a>
  12. <br>
  13. <a href="https://ci.appveyor.com/project/nex3/dart-sass"><img alt="Appveyor build status" src="https://ci.appveyor.com/api/projects/status/84rl9hvu8uoecgef?svg=true"></a>
  14. </td>
  15. </tr>
  16. </table>
  17. [sass]: https://sass-lang.com/
  18. This package is a distribution of [Dart Sass][], compiled to pure JavaScript
  19. with no native code or external dependencies. It provides a command-line `sass`
  20. executable and a Node.js API.
  21. [Dart Sass]: https://github.com/sass/dart-sass
  22. * [Usage](#usage)
  23. * [API](#api)
  24. * [See Also](#see-also)
  25. * [Behavioral Differences from Ruby Sass](#behavioral-differences-from-ruby-sass)
  26. ## Usage
  27. You can install Sass globally using `npm install -g sass` which will provide
  28. access to the `sass` executable. You can also add it to your project using
  29. `npm install --save-dev sass`. This provides the executable as well as a
  30. library:
  31. [npm]: https://www.npmjs.com/package/sass
  32. ```js
  33. var sass = require('sass');
  34. sass.render({file: scss_filename}, function(err, result) { /* ... */ });
  35. // OR
  36. var result = sass.renderSync({file: scss_filename});
  37. ```
  38. [See below](#api) for details on Dart Sass's JavaScript API.
  39. ## API
  40. When installed via npm, Dart Sass supports a JavaScript API that's fully
  41. compatible with [Node Sass][] (with a few exceptions listed below), with support
  42. for both the `render()` and `renderSync()` functions. See [the Sass
  43. website][js api] for full API documentation!
  44. [Node Sass]: https://github.com/sass/node-sass
  45. [js api]: https://sass-lang.com/documentation/js-api
  46. Note however that by default, **`renderSync()` is more than twice as fast as
  47. `render()`** due to the overhead of asynchronous callbacks. To avoid this
  48. performance hit, `render()` can use the [`fibers`][fibers] package to call
  49. asynchronous importers from the synchronous code path. To enable this, pass the
  50. `Fiber` class to the `fiber` option:
  51. [fibers]: https://www.npmjs.com/package/fibers
  52. ```js
  53. var sass = require("sass");
  54. var Fiber = require("fibers");
  55. sass.render({
  56. file: "input.scss",
  57. importer: function(url, prev, done) {
  58. // ...
  59. },
  60. fiber: Fiber
  61. }, function(err, result) {
  62. // ...
  63. });
  64. ```
  65. Both `render()` and `renderSync()` support the following options:
  66. * [`data`](https://github.com/sass/node-sass#data)
  67. * [`file`](https://github.com/sass/node-sass#file)
  68. * [`functions`](https://github.com/sass/node-sass#functions--v300---experimental)
  69. * [`importer`](https://github.com/sass/node-sass#importer--v200---experimental)
  70. * [`includePaths`](https://github.com/sass/node-sass#includepaths)
  71. * [`indentType`](https://github.com/sass/node-sass#indenttype)
  72. * [`indentWidth`](https://github.com/sass/node-sass#indentwidth)
  73. * [`indentedSyntax`](https://github.com/sass/node-sass#indentedsyntax)
  74. * [`linefeed`](https://github.com/sass/node-sass#linefeed)
  75. * [`omitSourceMapUrl`](https://github.com/sass/node-sass#omitsourcemapurl)
  76. * [`outFile`](https://github.com/sass/node-sass#outfile)
  77. * [`sourceMapContents`](https://github.com/sass/node-sass#sourcemapcontents)
  78. * [`sourceMapEmbed`](https://github.com/sass/node-sass#sourcemapembed)
  79. * [`sourceMapRoot`](https://github.com/sass/node-sass#sourcemaproot)
  80. * [`sourceMap`](https://github.com/sass/node-sass#sourcemap)
  81. * Only the `"expanded"` and `"compressed"` values of
  82. [`outputStyle`](https://github.com/sass/node-sass#outputstyle) are supported.
  83. No support is intended for the following options:
  84. * [`precision`](https://github.com/sass/node-sass#precision). Dart Sass defaults
  85. to a sufficiently high precision for all existing browsers, and making this
  86. customizable would make the code substantially less efficient.
  87. * [`sourceComments`](https://github.com/sass/node-sass#sourcecomments). Source
  88. maps are the recommended way of locating the origin of generated selectors.
  89. ## See Also
  90. * [Dart Sass][], from which this package is compiled, can be used either as a
  91. stand-alone executable or as a Dart library. Running Dart Sass on the Dart VM
  92. is substantially faster than running the pure JavaScript version, so this may
  93. be appropriate for performance-sensitive applications. The Dart API is also
  94. (currently) more user-friendly than the JavaScript API. See
  95. [the Dart Sass README][Using Dart Sass] for details on how to use it.
  96. * [Node Sass][], which is a wrapper around [LibSass][], the C++ implementation
  97. of Sass. Node Sass supports the same API as this package and is also faster
  98. (although it's usually a little slower than Dart Sass). However, it requires a
  99. native library which may be difficult to install, and it's generally slower to
  100. add features and fix bugs.
  101. [Using Dart Sass]: https://github.com/sass/dart-sass#using-dart-sass
  102. [Node Sass]: https://www.npmjs.com/package/node-sass
  103. [LibSass]: https://sass-lang.com/libsass
  104. ## Behavioral Differences from Ruby Sass
  105. There are a few intentional behavioral differences between Dart Sass and Ruby
  106. Sass. These are generally places where Ruby Sass has an undesired behavior, and
  107. it's substantially easier to implement the correct behavior than it would be to
  108. implement compatible behavior. These should all have tracking bugs against Ruby
  109. Sass to update the reference behavior.
  110. 1. `@extend` only accepts simple selectors, as does the second argument of
  111. `selector-extend()`. See [issue 1599][].
  112. 2. Subject selectors are not supported. See [issue 1126][].
  113. 3. Pseudo selector arguments are parsed as `<declaration-value>`s rather than
  114. having a more limited custom parsing. See [issue 2120][].
  115. 4. The numeric precision is set to 10. See [issue 1122][].
  116. 5. The indented syntax parser is more flexible: it doesn't require consistent
  117. indentation across the whole document. See [issue 2176][].
  118. 6. Colors do not support channel-by-channel arithmetic. See [issue 2144][].
  119. 7. Unitless numbers aren't `==` to unit numbers with the same value. In
  120. addition, map keys follow the same logic as `==`-equality. See
  121. [issue 1496][].
  122. 8. `rgba()` and `hsla()` alpha values with percentage units are interpreted as
  123. percentages. Other units are forbidden. See [issue 1525][].
  124. 9. Too many variable arguments passed to a function is an error. See
  125. [issue 1408][].
  126. 10. Allow `@extend` to reach outside a media query if there's an identical
  127. `@extend` defined outside that query. This isn't tracked explicitly, because
  128. it'll be irrelevant when [issue 1050][] is fixed.
  129. 11. Some selector pseudos containing placeholder selectors will be compiled
  130. where they wouldn't be in Ruby Sass. This better matches the semantics of
  131. the selectors in question, and is more efficient. See [issue 2228][].
  132. 12. The old-style `:property value` syntax is not supported in the indented
  133. syntax. See [issue 2245][].
  134. 13. The reference combinator is not supported. See [issue 303][].
  135. 14. Universal selector unification is symmetrical. See [issue 2247][].
  136. 15. `@extend` doesn't produce an error if it matches but fails to unify. See
  137. [issue 2250][].
  138. 16. Dart Sass currently only supports UTF-8 documents. We'd like to support
  139. more, but Dart currently doesn't support them. See [dart-lang/sdk#11744][],
  140. for example.
  141. [issue 1599]: https://github.com/sass/sass/issues/1599
  142. [issue 1126]: https://github.com/sass/sass/issues/1126
  143. [issue 2120]: https://github.com/sass/sass/issues/2120
  144. [issue 1122]: https://github.com/sass/sass/issues/1122
  145. [issue 2176]: https://github.com/sass/sass/issues/2176
  146. [issue 2144]: https://github.com/sass/sass/issues/2144
  147. [issue 1496]: https://github.com/sass/sass/issues/1496
  148. [issue 1525]: https://github.com/sass/sass/issues/1525
  149. [issue 1408]: https://github.com/sass/sass/issues/1408
  150. [issue 1050]: https://github.com/sass/sass/issues/1050
  151. [issue 2228]: https://github.com/sass/sass/issues/2228
  152. [issue 2245]: https://github.com/sass/sass/issues/2245
  153. [issue 303]: https://github.com/sass/sass/issues/303
  154. [issue 2247]: https://github.com/sass/sass/issues/2247
  155. [issue 2250]: https://github.com/sass/sass/issues/2250
  156. [dart-lang/sdk#11744]: https://github.com/dart-lang/sdk/issues/11744
  157. Disclaimer: this is not an official Google product.