-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy-minimize.js
39 lines (34 loc) · 1.47 KB
/
copy-minimize.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
const fs = require('fs');
const path = require('path');
const minifyHTML = require('html-minifier').minify;
const postcss = require('postcss');
const cssnano = require('cssnano');
const autoprefixer = require('autoprefixer');
function minifyAndCopyFile(filePath, destinationPath, type = 'txt') {
const fileContent = fs.readFileSync(path.join(__dirname, filePath), 'utf8');
switch (type) {
case 'html':
const minifiedHTML = minifyHTML(fileContent, {
removeAttributeQuotes: true,
collapseWhitespace: true,
removeComments: true
});
fs.writeFileSync(path.join(__dirname, destinationPath), minifiedHTML);
break;
case 'css':
postcss([autoprefixer, cssnano])
.process(fileContent, { from: 'undefined' })
.then(result => {
fs.writeFileSync(path.join(__dirname, destinationPath), result.css);
});
break;
default:
fs.copyFileSync(path.join(__dirname, filePath), path.join(__dirname, destinationPath));
}
}
minifyAndCopyFile('./src/index.html', './dist/index.html', 'html');
minifyAndCopyFile('./src/styles.css', './dist/styles.css', 'css');
minifyAndCopyFile('./src/favicon-32x32.png', './dist/favicon-32x32.png');
minifyAndCopyFile('./src/inter-v12-latin-500.woff2', './dist/inter-v12-latin-500.woff2');
minifyAndCopyFile('./src/inter-v12-latin-700.woff2', './dist/inter-v12-latin-700.woff2');
minifyAndCopyFile('./src/inter-v12-latin-regular.woff2', './dist/inter-v12-latin-regular.woff2');