-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-dist.js
36 lines (27 loc) · 961 Bytes
/
post-dist.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
const fs = require('fs');
const path = require('path');
// eslint-disable-next-line import/no-extraneous-dependencies
const purify = require('purify-css');
(async () => {
const files = fs.readdirSync('./dist', { encoding: 'utf8' });
const htmlFiles = files.filter(file => path.extname(file) === '.html');
const cssFile = files.find(file => path.extname(file) === '.css');
const content = ['dist/*.js', 'dist/*.html'];
const options = {
output: `./dist/${cssFile}`,
minify: true,
info: true,
// Logs out removed selectors.
// rejected: true,
};
purify(content, [`./dist/${cssFile}`], options);
htmlFiles.forEach(file => {
const src = fs.readFileSync(`./dist/${file}`, 'utf8');
if (!/\.html/g.test(src)) return;
const data = src.replace(/\.html/g, '');
fs.writeFile(`./dist/${file}`, data, err => {
if (err) throw err;
console.log(`🔧 ${file} html links sanitised`);
});
});
})();