forked from ankitskvmdam/clean-jsdoc-theme
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminify.js
60 lines (50 loc) · 1.58 KB
/
minify.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const uglify = require('uglify-js');
const csso = require('csso');
const path = require('path');
const fs = require('fs');
const pwd = path.join(__dirname);
const scriptsPath = path.join(pwd, 'static', 'scripts');
const cssPath = path.join(pwd, 'static', 'styles');
const uglifyFiles = [
{
src: path.join(scriptsPath, 'core.js'),
dest: path.join(scriptsPath, 'core.min.js')
},
{
src: path.join(scriptsPath, 'search.js'),
dest: path.join(scriptsPath, 'search.min.js')
},
{
src: path.join(scriptsPath, 'third-party', 'hljs-original.js'),
dest: path.join(scriptsPath, 'third-party', 'hljs.js')
},
{
src: path.join(scriptsPath, 'third-party', 'hljs-line-num-original.js'),
dest: path.join(scriptsPath, 'third-party', 'hljs-line-num.js')
},
{
src: path.join(scriptsPath, 'third-party', 'tocbot.js'),
dest: path.join(scriptsPath, 'third-party', 'tocbot.min.js')
}
];
const cssFilePaths = [
path.join(cssPath, 'clean-jsdoc-theme-base.css'),
path.join(cssPath, 'clean-jsdoc-theme-dark.css'),
path.join(cssPath, 'clean-jsdoc-theme-light.css')
];
let css = '';
for (const p of cssFilePaths) {
css += fs.readFileSync(p, 'utf-8');
}
const minifiedCss = csso.minify(css, { restructure: false });
fs.writeFileSync(
path.join(cssPath, 'clean-jsdoc-theme.min.css'),
minifiedCss.css
);
for (const f of uglifyFiles) {
const data = fs.readFileSync(f.src, 'utf-8');
const out = uglify.minify(data, {
compress: true
});
fs.writeFileSync(f.dest, out.code);
}