This repository was archived by the owner on Jun 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpurify.js
More file actions
46 lines (38 loc) · 1.22 KB
/
purify.js
File metadata and controls
46 lines (38 loc) · 1.22 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
43
44
45
46
// Script to remove all unnecessary css from the css source files
const purify = require("purify-css")
var content = []
var css = []
var options = {
output: 'public/css/style-clean.css',
info: true,
minify: true
};
var path = require('path'), fs = require('fs');
function fromDir(startPath, filter, callback) {
if (!fs.existsSync(startPath)) {
console.log("no dir ", startPath);
return;
}
var files = fs.readdirSync(startPath);
for (var i = 0; i < files.length; i++) {
var filename = path.join(startPath, files[i]);
var stat = fs.lstatSync(filename);
if (stat.isDirectory()) {
fromDir(filename, filter, callback); //recurse
} else if (filter.test(filename)) callback(filename);
}
;
};
fromDir('./public', /\.html$/, function (filename) {
console.log('-- found: ', filename);
content.push(path.relative('./', filename));
});
fromDir('./public', /\.js$/, function (filename) {
console.log('-- found: ', filename);
content.push(path.relative('./', filename));
});
fromDir('./public', /\.css$/, function (filename) {
console.log('-- found: ', filename);
css.push(path.relative('./', filename));
});
purify(content, css, options);