forked from Netcentric/fe-build
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderPostcss.js
More file actions
42 lines (37 loc) · 1.33 KB
/
Copy pathrenderPostcss.js
File metadata and controls
42 lines (37 loc) · 1.33 KB
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
33
34
35
36
37
38
39
40
41
42
const postcss = require('postcss');
const { log } = require('./log');
module.exports = function renderPostcss(input, outFile, config, cb) {
const { plugins, failOnError } = config.postcss;
try {
// try to dynamic load of postcss plugins
/* eslint-disable */
const runPlugins = plugins.map(plugin => require(plugin));
const map = config.general.isProduction ? false : { inline: true, prev: input.map.toString() } ;
/* eslint-enable */
// run postcss plugins at sass output
postcss(runPlugins).process(input.css.toString(), { from: outFile, map })
.then((result) => {
// check all warnings
const warns = result.warnings();
if (warns && warns.length > 0) {
// log warnings
return result.warnings().forEach((warn) => {
log(__filename, 'error', warn.toString(), 'error');
// exit if fail on error is defined
if (failOnError) {
process.exit(1);
}
});
}
// success and return
log(__filename, `Postcss applied ${plugins.join(',')} - `, input.destFile, 'success');
return cb(result);
});
} catch (error) {
log(__filename, 'Postcss error', error.message, 'error');
// exit if fail on error is defined
if (failOnError) {
process.exit(1);
}
}
};