-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-css.js
45 lines (32 loc) · 1.14 KB
/
build-css.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
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Build CSS from the array of files in JSON style array.
> node build-css.js source.json target.css
*/
import CleanCSS from 'clean-css';
import fs from 'fs';
import { green } from './builder/log.js';
// Arguments
const args = process.argv.slice(2);
if (args.length < 2) {
throw new Error("build-css requires the arguments: source.json target.css");
}
const source = args[0].replace(/^\.\//, '');
const target = args[1] || 'module.css';
function logError(error) {
if (error) { throw error; }
}
// Minify the files
const minified = new CleanCSS({
inline: ['all']
}).minify([source]);
fs.writeFile(target.replace(/\.css$/, '.min.css'), minified.styles, logError);
const beautified = new CleanCSS({
inline: ['all'],
format: 'beautify'
}).minify([source]);
fs.writeFile(target, beautified.styles, logError);
console.log(green, 'CSS ' + source + ' ('
+ (minified.stats.originalSize / 1000).toFixed(1) + 'kB) packaged to',
'\n' + target + ' (' + (beautified.stats.minifiedSize / 1000).toFixed(1) + 'kB)\n'
+ target.replace(/\.css$/, '.min.css') + ' (' + (minified.stats.minifiedSize / 1000).toFixed(1) + 'kB)\n'
);