csstools-postcss-sass-pre-release
Version:
Use Sass as a PostCSS plugin
147 lines (110 loc) • 3.32 kB
Markdown
[![NPM Version][npm-img]][npm-url]
[![Linux Build Status][cli-img]][cli-url]
[![Windows Build Status][win-img]][win-url]
[![Support Chat][git-img]][git-url]
[] lets you use [Sass] as a [PostCSS] plugin.
```scss
$font-stack: Helvetica, sans-serif;
$primary-color:
:root {
color: $primary-color;
font: 100% $font-stack;
}
/* becomes */
:root {
color:
font: 100% Helvetica, sans-serif;
}
```
[] uses [dart-sass], letting you safely run transforms before and
after Sass, watching for changes to Sass imports, and preserving source maps.
Add [PostCSS Sass] to your build tool:
```sh
npm install postcss @csstools/postcss-sass --save-dev
```
Use [PostCSS Sass] to process your CSS:
```js
require('@csstools/postcss-sass').process(YOUR_CSS);
```
Use [PostCSS Sass] as a plugin:
```js
postcss([
require('@csstools/postcss-sass')(/* node-sass options */)
]).process(YOUR_CSS);
```
The standard CSS parser included with PostCSS may not be able to parse SCSS
specific features like inline comments. To accurately parse SCSS, use
the [SCSS Parser].
```bash
npm install postcss-scss --save-dev
```
```js
const postcss = require('postcss');
const postcssSass = require('@csstools/postcss-sass');
postcss([
postcssSass(/* pluginOptions */)
]).process(YOUR_CSS, {
syntax: 'postcss-scss'
});
```
Add [Gulp PostCSS] to your build tool:
```sh
npm install gulp-postcss --save-dev
```
Use [PostCSS Sass] in your Gulpfile:
```js
var postcss = require('gulp-postcss');
gulp.task('css', function () {
return gulp.src('./src/*.css').pipe(
postcss([
require('@csstools/postcss-sass')(/* node-sass options */)
])
).pipe(
gulp.dest('.')
);
});
```
Add [Grunt PostCSS] to your build tool:
```sh
npm install grunt-postcss --save-dev
```
Use [PostCSS Sass] in your Gruntfile:
```js
grunt.loadNpmTasks('grunt-postcss');
grunt.initConfig({
postcss: {
options: {
use: [
require('@csstools/postcss-sass')(/* node-sass options */)
]
},
dist: {
src: '*.css'
}
}
});
```
[] options are directly forwarded to [dart-sass options].
[]: https://img.shields.io/travis/jonathantneal/postcss-sass.svg
[]: https://travis-ci.org/jonathantneal/postcss-sass
[]: https://img.shields.io/badge/support-chat-blue.svg
[]: https://gitter.im/postcss/postcss
[]: https://img.shields.io/npm/v/@csstools/postcss-sass.svg
[]: https://www.npmjs.com/package/@csstools/postcss-sass
[]: https://img.shields.io/appveyor/ci/jonathantneal/postcss-sass.svg
[]: https://ci.appveyor.com/project/jonathantneal/postcss-sass
[]: https://github.com/postcss/gulp-postcss
[]: https://github.com/nDmitry/grunt-postcss
[]: https://github.com/sass/dart-sass
[]: https://github.com/sass/dart-sass#javascript-api
[]: https://github.com/postcss/postcss
[]: https://github.com/jonathantneal/postcss-sass
[]: https://github.com/sass/dart-sass
[]: https://github.com/postcss/postcss-scss