-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcssnano.js
32 lines (28 loc) · 908 Bytes
/
cssnano.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import postCSS from 'postcss';
import { plugin } from 'postcss';
import preset from 'cssnano-preset-default';
// svgo uses fs, so we can't use it
const { plugins } = preset({ svgo: true });
function initializePlugin(plugin, css, result) {
if (Array.isArray(plugin)) {
const [processor, opts] = plugin;
if (
typeof opts === 'undefined' ||
(typeof opts === 'object' && !opts.exclude)
) {
return Promise.resolve(processor(opts)(css, result));
}
} else {
return Promise.resolve(plugin()(css, result));
}
// Handle excluded plugins
return Promise.resolve();
}
const cssNano = plugin('cssnano', () => {
return (css, result) => {
return plugins.reduce((promise, plugin) => {
return promise.then(initializePlugin.bind(null, plugin, css, result));
}, Promise.resolve());
};
});
export default (cssString) => postCSS([cssNano]).process(cssString);