Skip to content

Commit 1e684db

Browse files
committed
Added an example and a test to pass options to PostCSS
1 parent 75d52cc commit 1e684db

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,26 @@ gulp.task('css', function () {
3030
});
3131
```
3232

33+
## Passing additional options to PostCSS
34+
35+
The second optional argument to gulp-postcss is passed to PostCSS.
36+
37+
This, for instance, may be used to enable custom syntax:
38+
39+
```js
40+
var gulp = require('gulp');
41+
var postcss = require('gulp-postcss');
42+
var nested = require('postcss-nested');
43+
var scss = require('postcss-scss');
44+
45+
gulp.task('default', function () {
46+
var processors = [nested];
47+
return gulp.src('in.css')
48+
.pipe(postcss(processors, {syntax: scss}))
49+
.pipe(gulp.dest('out'));
50+
});
51+
```
52+
3353
## Using a custom processor
3454

3555
```js
@@ -74,6 +94,9 @@ return gulp.src('./src/*.css')
7494

7595
## Changelog
7696

97+
* 6.0.1
98+
* Added an example and a test to pass options to PostCSS (e.g. `syntax` option)
99+
77100
* 6.0.0
78101
* Updated PostCSS to version 5.0.0
79102

test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,40 @@ describe('PostCSS Guidelines', function () {
245245

246246
})
247247

248+
it('should pass options down to PostCSS', function (cb) {
249+
250+
var customSyntax = function () {}
251+
var options = {
252+
syntax: customSyntax
253+
}
254+
255+
var stream = postcss([ doubler ], options)
256+
var cssPath = __dirname + '/src/fixture.css'
257+
postcssStub.process.returns(Promise.resolve({
258+
css: ''
259+
, warnings: function () {
260+
return []
261+
}
262+
}))
263+
264+
stream.on('data', function () {
265+
var resultOptions = postcssStub.process.getCall(0).args[1]
266+
// remove automatically set options
267+
delete resultOptions.from
268+
delete resultOptions.to
269+
delete resultOptions.map
270+
assert.deepEqual(resultOptions, options)
271+
cb()
272+
})
273+
274+
stream.write(new gutil.File({
275+
contents: new Buffer('a {}')
276+
, path: cssPath
277+
}))
278+
279+
stream.end()
280+
281+
})
248282

249283
})
250284

0 commit comments

Comments
 (0)