|
1 | 1 | # reduce-postcss
|
2 | 2 | Plugin for [reduce-css](https://github.com/zoubin/reduce-css) to pack postcss modules.
|
| 3 | + |
| 4 | +[](https://www.npmjs.org/package/reduce-css-postcss) |
| 5 | + |
| 6 | +[](https://www.npmjs.org/package/reduce-css-postcss) |
| 7 | +[](https://travis-ci.org/zoubin/reduce-css-postcss) |
| 8 | +[](https://coveralls.io/github/zoubin/reduce-css-postcss) |
| 9 | +[](https://david-dm.org/zoubin/reduce-css-postcss) |
| 10 | +[](https://david-dm.org/zoubin/reduce-css-postcss#info=devDependencies) |
| 11 | + |
| 12 | +## Example |
| 13 | + |
| 14 | +See files in the example directory. |
| 15 | + |
| 16 | +```javascript |
| 17 | +var gulp = require('gulp') |
| 18 | +var del = require('del') |
| 19 | +var reduce = require('reduce-css') |
| 20 | +var postcss = require('reduce-css-postcss') |
| 21 | +var path = require('path') |
| 22 | +var fixtures = path.resolve.bind(path) |
| 23 | + |
| 24 | +gulp.task('clean', function () { |
| 25 | + return del('build') |
| 26 | +}) |
| 27 | + |
| 28 | +gulp.task('single-bundle', ['clean'], function () { |
| 29 | + return reduce |
| 30 | + .on('error', console.log.bind(console)) |
| 31 | + .on('log', console.log.bind(console)) |
| 32 | + .on('instance', function (b) { |
| 33 | + b.plugin(postcss) |
| 34 | + }) |
| 35 | + .src('*.css', { |
| 36 | + basedir: fixtures('src'), |
| 37 | + factor: 'common.css', |
| 38 | + }) |
| 39 | + .pipe(reduce.dest('build', null, { |
| 40 | + maxSize: 0, |
| 41 | + assetOutFolder: fixtures('build', 'images'), |
| 42 | + })) |
| 43 | +}) |
| 44 | + |
| 45 | +gulp.task('watch-single-bundle', ['clean'], function () { |
| 46 | + reduce.watch() |
| 47 | + .on('error', console.log.bind(console)) |
| 48 | + .on('log', console.log.bind(console)) |
| 49 | + .on('instance', function (b) { |
| 50 | + b.plugin(postcss) |
| 51 | + }) |
| 52 | + .src('*.css', { |
| 53 | + basedir: fixtures('src'), |
| 54 | + factor: 'common.css', |
| 55 | + }) |
| 56 | + .pipe(reduce.dest, 'build', null, { |
| 57 | + maxSize: 0, |
| 58 | + assetOutFolder: fixtures('build', 'images'), |
| 59 | + }) |
| 60 | +}) |
| 61 | + |
| 62 | +gulp.task('multiple-bundles', ['clean'], function () { |
| 63 | + return reduce |
| 64 | + .on('error', console.log.bind(console)) |
| 65 | + .on('log', console.log.bind(console)) |
| 66 | + .on('instance', function (b) { |
| 67 | + b.plugin(postcss) |
| 68 | + }) |
| 69 | + .src('*.css', { |
| 70 | + basedir: fixtures('src'), |
| 71 | + factor: { |
| 72 | + needFactor: true, |
| 73 | + common: 'common.css', |
| 74 | + }, |
| 75 | + }) |
| 76 | + .pipe(reduce.dest('build', null, { |
| 77 | + maxSize: 0, |
| 78 | + useHash: true, |
| 79 | + assetOutFolder: fixtures('build', 'images'), |
| 80 | + })) |
| 81 | +}) |
| 82 | + |
| 83 | +gulp.task('watch-multiple-bundles', ['clean'], function () { |
| 84 | + reduce.watch() |
| 85 | + .on('error', console.log.bind(console)) |
| 86 | + .on('log', console.log.bind(console)) |
| 87 | + .on('instance', function (b) { |
| 88 | + b.plugin(postcss) |
| 89 | + }) |
| 90 | + .src('*.css', { |
| 91 | + basedir: fixtures('src'), |
| 92 | + factor: { |
| 93 | + needFactor: true, |
| 94 | + common: 'common.css', |
| 95 | + }, |
| 96 | + }) |
| 97 | + .pipe(reduce.dest, 'build', null, { |
| 98 | + maxSize: 0, |
| 99 | + useHash: true, |
| 100 | + assetOutFolder: fixtures('build', 'images'), |
| 101 | + }) |
| 102 | +}) |
| 103 | + |
| 104 | + |
| 105 | +``` |
| 106 | + |
| 107 | +## options |
| 108 | + |
| 109 | +### processorFilter |
| 110 | +Type: `Function` |
| 111 | + |
| 112 | +Receive a [pipeline](https://github.com/zoubin/postcss-processor-splicer) instance, |
| 113 | +through which you can add, remove, or customize postcss plugins to apply. |
| 114 | + |
| 115 | +Type: `Array` |
| 116 | + |
| 117 | +Specify extra postcss plugins to apply. |
| 118 | + |
| 119 | +#### Default plugins |
| 120 | + |
| 121 | +* [postcss-simple-import](https://github.com/zoubin/postcss-simple-import) |
| 122 | +* [postcss-custom-url](https://github.com/zoubin/postcss-custom-url) |
| 123 | +* [postcss-advanced-variables](https://github.com/jonathantneal/postcss-advanced-variables) |
| 124 | +* [postcss-mixins](https://github.com/postcss/postcss-mixins) |
| 125 | +* [postcss-nested](https://github.com/postcss/postcss-nested) |
| 126 | +* [postcss-extend](https://github.com/travco/postcss-extend) |
| 127 | +* [autoprefixer](https://github.com/postcss/autoprefixer) |
| 128 | + |
| 129 | + |
0 commit comments