Skip to content

Commit 3f86853

Browse files
committed
Documentation updates
1 parent 2640ec3 commit 3f86853

File tree

1 file changed

+70
-26
lines changed

1 file changed

+70
-26
lines changed

README.md

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Compiles CSS packages with:
1515
* [postcss-custom-media](https://github.com/postcss/postcss-custom-media)
1616
* [autoprefixer](https://github.com/postcss/autoprefixer)
1717

18-
In addition each imported file is linted with [postcss-bem-linter](https://github.com/postcss/postcss-bem-linter) and minification is provided by [cssnano](http://cssnano.co/).
18+
Each imported file is linted with [postcss-bem-linter](https://github.com/postcss/postcss-bem-linter) and minification is provided by [cssnano](http://cssnano.co/). Additional plugins can be added via the configuration options.
1919

2020
## Installation
2121

@@ -64,7 +64,74 @@ Examples:
6464
$ cat input.css | suitcss | grep background-color
6565
```
6666

67-
### Configuration
67+
### Node.js
68+
69+
Returns a [PostCSS promise](https://github.com/postcss/postcss/blob/master/docs/api.md#lazyresult-class)
70+
71+
```js
72+
var preprocessor = require('suitcss-preprocessor');
73+
var fs = require('fs');
74+
75+
var css = fs.readFileSync('src/components/index.css', 'utf8');
76+
77+
preprocessor(css, {
78+
root: 'path/to/css',
79+
minify: true,
80+
}).then(function(result) {
81+
fs.writeFileSync('build/bundle.css', result.css);
82+
});
83+
```
84+
85+
#### Options
86+
87+
##### `root`
88+
89+
* Type: `String`
90+
* Default: `process.cwd()`
91+
92+
Where to resolve imports from. Passed to [`postcss-import`](https://github.com/postcss/postcss-import/blob/master/README.md#root).
93+
94+
##### `minify`
95+
96+
* Type: `Boolean`
97+
* Default: `false`
98+
99+
If set to `true` then the output is minified by [`cssnano`](http://cssnano.co/).
100+
101+
##### `beforeLint`
102+
103+
* Type: `Function`
104+
* Default: `false`
105+
106+
Called with the imported CSS before it's passed to `postcss-bem-linter`. This allows you to transform the CSS first and it must return the css string.
107+
108+
Third paramater is the options object containing any PostCSS configuration you may need.
109+
110+
```js
111+
{
112+
beforeLint(css, filename, options) {
113+
// Do something to the imported css
114+
return css;
115+
}
116+
}
117+
```
118+
119+
##### `config`
120+
121+
* Type: `Object`
122+
* Default: [various](https://github.com/suitcss/preprocessor/blob/master/lib/index.js#L23)
123+
124+
A list of plugins and their options that are passed to PostCSS. This can be used to add new plugins and/or configure existing ones.
125+
126+
```js
127+
config: {
128+
use: ['stylelint', 'postcss-property-lookup'],
129+
autoprefixer: { browsers: ['> 1%', 'IE 7'], cascade: false },
130+
'postcss-calc': { preserve: true }
131+
}
132+
```
133+
134+
### Plugin configuration
68135

69136
Creating a configuration file allows options to be passed to the individual PostCSS plugins. It can be passed to the `suitcss` CLI via the `-c` flag and can be either JavaScript or JSON
70137

@@ -90,7 +157,7 @@ Options are merged recursively with the defaults. For example, adding new plugin
90157

91158
By default the preprocessor uses all necessary plugins to build SUIT components. However additional plugins can be installed into a project and then added to the `use` array.
92159

93-
This **will not** work with the preprocessor installed globally. Instead rely on the convenience of `npm run <script>`
160+
**Note**: This will not work with the preprocessor installed globally. Instead rely on the convenience of `npm run <script>`
94161

95162
```js
96163
module.exports = {
@@ -154,29 +221,6 @@ var result = [
154221
];
155222
```
156223

157-
### Node.js
158-
159-
Returns a [PostCSS promise](https://github.com/postcss/postcss/blob/master/docs/api.md#lazyresult-class)
160-
161-
```js
162-
var preprocessor = require('suitcss-preprocessor');
163-
var fs = require('fs');
164-
165-
var css = fs.readFileSync('src/components/index.css', 'utf8');
166-
167-
preprocessor(css, {
168-
root: 'path/to/css',
169-
minify: true,
170-
config: {
171-
use: ['postcss-property-lookup'],
172-
autoprefixer: { browsers: ['> 1%', 'IE 7'], cascade: false },
173-
'postcss-calc': { preserve: true }
174-
}
175-
}).then(function(result) {
176-
fs.writeFileSync('build/bundle.css', result.css);
177-
});
178-
```
179-
180224
## Acknowledgements
181225

182226
Based on [Myth](https://github.com/segmentio/myth) by Segment.io.

0 commit comments

Comments
 (0)