-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxhtml
More file actions
47 lines (41 loc) · 1.47 KB
/
Copy pathxhtml
File metadata and controls
47 lines (41 loc) · 1.47 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
47
#!/usr/bin/env node
// node_modules/inliner/lib/tasks/js.js:40 src.indexOf('//') 修改为: src.indexOf('/')
const Inliner = require('inliner');
const fs = require('fs');
const program = require('./js/dialog').commander();
program
.version('1.0.0')
.option('-u, --url <http://127.0.0.1:3000/test>', 'url of api')
.option('-o, --out [out.html]', 'output html file', 'out.html')
.parse(process.argv);
let { url, out } = program;
!/\.html$/.test(out) && (out = `${out}.html`);
if (!url) {
console.log('url不能为空');
process.exit(0);
}
const options = {
// inlinemin: true, // 是否将min的js加入到script
// encoding: 'utf8', // 指定网页的编码
nosvg: false, // by default, DO compress SVG with SVGO
preserveComments: false,// 是否跳过绝对注释
skipAbsoluteUrls: true,// 是否跳过绝对路径
collapseWhitespace: false,// 是否去除空白
compressJS: false, // 是否压缩js
compressCSS: false, // 是否压缩css
iesafe: false, // 是否压缩css
images: false, // 是否转化图片为base64
videos: false, // 是否转化视频为base64
};
const inliner = new Inliner(url, options, function (error, html) {
if (error) {
const message = Inliner.errors[error.code] || error.message;
console.error(message);
} else {
fs.writeFileSync(out, html);
console.log('html已经写入'+out);
}
});
inliner.on('progress', function (event) {
console.log(event);
});