@oipage/cli 0.3.0-alpha.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +11 -11
- package/AUTHORS.txt +6 -6
- package/CHANGELOG +47 -47
- package/LICENSE +20 -20
- package/README.md +132 -132
- package/bin/WebSocket/decodeWsFrame.js +43 -43
- package/bin/WebSocket/encodeWsFrame.js +28 -28
- package/bin/WebSocket/headersToJSON.js +26 -26
- package/bin/WebSocket/index.js +106 -106
- package/bin/data/mineTypes.json +104 -104
- package/bin/disk.js +42 -42
- package/bin/help.js +55 -55
- package/bin/intercept.js +15 -15
- package/bin/network.js +21 -21
- package/bin/notebook/index.js +8 -8
- package/bin/proxy.js +82 -82
- package/bin/run +146 -146
- package/bin/serve.js +318 -318
- package/bin/template/404.html +184 -184
- package/bin/tools/deleteEmptyFolder.js +33 -33
- package/bin/tools/format.js +75 -75
- package/bin/tools/isBinary.js +83 -83
- package/bin/tools/network.js +42 -42
- package/bin/tools/openBrowser.js +34 -34
- package/bin/tools/resolve404.js +98 -98
- package/bin/tools/resolveImport.js +96 -96
- package/bin/website-htmls/components/ui-select-file/index.html +8 -8
- package/bin/website-htmls/components/ui-select-file/index.js +42 -42
- package/bin/website-htmls/components/ui-select-file/index.scss +44 -44
- package/bin/website-htmls/dialogs/imageSize/index.html +54 -54
- package/bin/website-htmls/dialogs/imageSize/index.js +53 -53
- package/bin/website-htmls/dialogs/imageSize/index.scss +140 -140
- package/bin/website-htmls/dialogs/index.js +52 -52
- package/bin/website-htmls/images/addFile.svg +1 -1
- package/bin/website-htmls/images/img-to-pdf.svg +1 -1
- package/bin/website-htmls/index.html +17 -17
- package/bin/website-htmls/main.js +13 -13
- package/bin/website-htmls/pages/App/index.html +6 -6
- package/bin/website-htmls/pages/App/index.js +22 -22
- package/bin/website-htmls/pages/App/index.scss +43 -43
- package/bin/website-htmls/pages/appStore/index.html +7 -7
- package/bin/website-htmls/pages/appStore/index.js +19 -19
- package/bin/website-htmls/pages/appStore/index.scss +54 -54
- package/bin/website-htmls/pages/chart/index.html +8 -8
- package/bin/website-htmls/pages/chart/index.js +72 -72
- package/bin/website-htmls/pages/chart/index.scss +71 -71
- package/bin/website-htmls/pages/home/index.html +19 -19
- package/bin/website-htmls/pages/home/index.js +19 -19
- package/bin/website-htmls/pages/home/index.scss +87 -87
- package/bin/website-htmls/pages/image-editor/index.html +27 -27
- package/bin/website-htmls/pages/image-editor/index.js +106 -106
- package/bin/website-htmls/pages/image-editor/index.scss +69 -69
- package/bin/website-htmls/pages/img-to-pdf/index.html +3 -3
- package/bin/website-htmls/pages/img-to-pdf/index.js +44 -44
- package/bin/website-htmls/pages/img-to-pdf/index.scss +9 -9
- package/bin/website-htmls/pages/recorder-screen/index.html +15 -15
- package/bin/website-htmls/pages/recorder-screen/index.js +227 -227
- package/bin/website-htmls/pages/recorder-screen/index.scss +52 -52
- package/bin/website-htmls/router.config.js +29 -29
- package/bin/website-htmls/styles/common.css +44 -44
- package/bin/website-htmls/styles/normalize.css +94 -94
- package/bin/website-plugins/intercept/chart.js +33 -33
- package/bin/website-plugins/intercept/getPackage.js +17 -17
- package/bin/website-plugins/intercept/head.js +8 -8
- package/bin/website-plugins/intercept/index.js +8 -8
- package/bin/website-plugins/intercept/oipage-vislite-intercept.js +55 -55
- package/bin/website-plugins/intercept/oipage-zipaper-intercept.js +36 -36
- package/bin/website-plugins/loader/index.js +11 -11
- package/bin/website-plugins/loader/oipage-html-loader.js +7 -7
- package/bin/website-plugins/loader/oipage-scss-loader.js +149 -149
- package/docs/config.md +106 -106
- package/package.json +42 -42
- package/src/index.js +29 -29
- package/types/serve.d.ts +83 -83
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
// 参考:https://github.com/zxl20070701/zxl20070701.github.io/blob/master/bin/loader/scss.js
|
|
2
|
-
let toSelector = function (preSelectorArray, deep) {
|
|
3
|
-
let selectors = preSelectorArray[0], i, j, k;
|
|
4
|
-
for (i = 1; i < deep; i++) {
|
|
5
|
-
let temp = [];
|
|
6
|
-
for (j = 0; j < selectors.length; j++) {
|
|
7
|
-
for (k = 0; k < preSelectorArray[i].length; k++) {
|
|
8
|
-
temp.push(selectors[j] + preSelectorArray[i][k]);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
selectors = temp;
|
|
12
|
-
}
|
|
13
|
-
return "\n" + (selectors.join(',')) + "{\n";
|
|
14
|
-
};
|
|
15
|
-
let analyseBlock = function (source) {
|
|
16
|
-
let i = -1, currentChar = null;
|
|
17
|
-
let next = function () {
|
|
18
|
-
currentChar = i++ < source.length - 1 ? source[i] : null;
|
|
19
|
-
return currentChar;
|
|
20
|
-
}
|
|
21
|
-
let nextNValue = function (n) {
|
|
22
|
-
return source.substring(i, n + i > source.length ? source.length : n + i);
|
|
23
|
-
}
|
|
24
|
-
let blocks = [];
|
|
25
|
-
let currentBlock = "";
|
|
26
|
-
next();
|
|
27
|
-
while (true) {
|
|
28
|
-
while (new RegExp("[\\x20\\t\\r\\n\\f]").test(currentChar)) {
|
|
29
|
-
next();
|
|
30
|
-
}
|
|
31
|
-
if (currentChar == null) break;
|
|
32
|
-
if (nextNValue(2) == '/*') {
|
|
33
|
-
|
|
34
|
-
next();
|
|
35
|
-
next();
|
|
36
|
-
currentBlock = "/*";
|
|
37
|
-
|
|
38
|
-
while (nextNValue(2) != '*/' && currentChar != null) {
|
|
39
|
-
currentBlock += currentChar;
|
|
40
|
-
next();
|
|
41
|
-
}
|
|
42
|
-
if (currentChar == null) {
|
|
43
|
-
throw new Error('The comment is not closed.');
|
|
44
|
-
}
|
|
45
|
-
currentBlock += "*/";
|
|
46
|
-
next();
|
|
47
|
-
next();
|
|
48
|
-
blocks.push({
|
|
49
|
-
value: currentBlock,
|
|
50
|
-
type: "comment-double"
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
else if (nextNValue(2) == '//') {
|
|
54
|
-
currentBlock = '';
|
|
55
|
-
|
|
56
|
-
while (currentChar != '\n' && currentChar != null) {
|
|
57
|
-
currentBlock += currentChar;
|
|
58
|
-
next();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
blocks.push({
|
|
62
|
-
value: currentBlock,
|
|
63
|
-
type: "comment-single"
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
else if (currentChar == '}') {
|
|
68
|
-
|
|
69
|
-
blocks.push({
|
|
70
|
-
value: "}",
|
|
71
|
-
type: "end"
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
next();
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
|
|
79
|
-
currentBlock = '';
|
|
80
|
-
while (currentChar != '{' && currentChar != ';' && currentChar != null) {
|
|
81
|
-
currentBlock += currentChar;
|
|
82
|
-
next();
|
|
83
|
-
}
|
|
84
|
-
if (currentChar == null) {
|
|
85
|
-
throw new Error('Statement or code block missing closure.');
|
|
86
|
-
}
|
|
87
|
-
blocks.push({
|
|
88
|
-
value: currentBlock + currentChar,
|
|
89
|
-
type: {
|
|
90
|
-
'{': "begin",
|
|
91
|
-
';': 'statement'
|
|
92
|
-
}[currentChar]
|
|
93
|
-
});
|
|
94
|
-
next();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return blocks;
|
|
98
|
-
};
|
|
99
|
-
module.exports = function (source) {
|
|
100
|
-
this.setFileType("application/javascript");
|
|
101
|
-
let blocks = analyseBlock(source + "");
|
|
102
|
-
let i, j, cssCode = "", preSelectorArray = [], deep = 0;
|
|
103
|
-
for (i = 0; i < blocks.length; i++) {
|
|
104
|
-
if (blocks[i].type == 'comment-double') {
|
|
105
|
-
cssCode += blocks[i].value;
|
|
106
|
-
}
|
|
107
|
-
else if (blocks[i].type == 'comment-single') {
|
|
108
|
-
cssCode += "\n/* " + blocks[i].value + " */\n";
|
|
109
|
-
}
|
|
110
|
-
else if (blocks[i].type == 'begin') {
|
|
111
|
-
let preSplit = blocks[i].value.split(',');
|
|
112
|
-
let preSelect = [];
|
|
113
|
-
for (j = 0; j < preSplit.length; j++) {
|
|
114
|
-
preSelect[j] = preSplit[j].replace(/\{$/, '').trim();
|
|
115
|
-
if (/^&/.test(preSelect[j])) {
|
|
116
|
-
preSelect[j] = preSelect[j].replace(/^&/, '');
|
|
117
|
-
} else {
|
|
118
|
-
preSelect[j] = " " + preSelect[j];
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
preSelectorArray[deep] = preSelect;
|
|
122
|
-
deep += 1;
|
|
123
|
-
}
|
|
124
|
-
else if (blocks[i].type == 'end') {
|
|
125
|
-
deep -= 1;
|
|
126
|
-
}
|
|
127
|
-
else if (blocks[i].type == 'statement') {
|
|
128
|
-
j = 1;
|
|
129
|
-
let preType = blocks[i - j].type;
|
|
130
|
-
while (['comment-double', 'comment-single'].indexOf(preType) > -1) {
|
|
131
|
-
j += 1;
|
|
132
|
-
preType = blocks[i - j].type;
|
|
133
|
-
}
|
|
134
|
-
if (['end', 'begin'].indexOf(preType) > -1) {
|
|
135
|
-
cssCode += toSelector(preSelectorArray, deep);
|
|
136
|
-
}
|
|
137
|
-
cssCode += "\n" + blocks[i].value + "\n";
|
|
138
|
-
j = 1;
|
|
139
|
-
let nextType = blocks[i + j].type;
|
|
140
|
-
while (['comment-double', 'comment-single'].indexOf(nextType) > -1) {
|
|
141
|
-
j += 1;
|
|
142
|
-
nextType = blocks[i + j].type;
|
|
143
|
-
}
|
|
144
|
-
if (['end', 'begin'].indexOf(nextType) > -1) {
|
|
145
|
-
cssCode += "\n}\n";
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return `export default ${JSON.stringify(cssCode)}`;
|
|
1
|
+
// 参考:https://github.com/zxl20070701/zxl20070701.github.io/blob/master/bin/loader/scss.js
|
|
2
|
+
let toSelector = function (preSelectorArray, deep) {
|
|
3
|
+
let selectors = preSelectorArray[0], i, j, k;
|
|
4
|
+
for (i = 1; i < deep; i++) {
|
|
5
|
+
let temp = [];
|
|
6
|
+
for (j = 0; j < selectors.length; j++) {
|
|
7
|
+
for (k = 0; k < preSelectorArray[i].length; k++) {
|
|
8
|
+
temp.push(selectors[j] + preSelectorArray[i][k]);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
selectors = temp;
|
|
12
|
+
}
|
|
13
|
+
return "\n" + (selectors.join(',')) + "{\n";
|
|
14
|
+
};
|
|
15
|
+
let analyseBlock = function (source) {
|
|
16
|
+
let i = -1, currentChar = null;
|
|
17
|
+
let next = function () {
|
|
18
|
+
currentChar = i++ < source.length - 1 ? source[i] : null;
|
|
19
|
+
return currentChar;
|
|
20
|
+
}
|
|
21
|
+
let nextNValue = function (n) {
|
|
22
|
+
return source.substring(i, n + i > source.length ? source.length : n + i);
|
|
23
|
+
}
|
|
24
|
+
let blocks = [];
|
|
25
|
+
let currentBlock = "";
|
|
26
|
+
next();
|
|
27
|
+
while (true) {
|
|
28
|
+
while (new RegExp("[\\x20\\t\\r\\n\\f]").test(currentChar)) {
|
|
29
|
+
next();
|
|
30
|
+
}
|
|
31
|
+
if (currentChar == null) break;
|
|
32
|
+
if (nextNValue(2) == '/*') {
|
|
33
|
+
|
|
34
|
+
next();
|
|
35
|
+
next();
|
|
36
|
+
currentBlock = "/*";
|
|
37
|
+
|
|
38
|
+
while (nextNValue(2) != '*/' && currentChar != null) {
|
|
39
|
+
currentBlock += currentChar;
|
|
40
|
+
next();
|
|
41
|
+
}
|
|
42
|
+
if (currentChar == null) {
|
|
43
|
+
throw new Error('The comment is not closed.');
|
|
44
|
+
}
|
|
45
|
+
currentBlock += "*/";
|
|
46
|
+
next();
|
|
47
|
+
next();
|
|
48
|
+
blocks.push({
|
|
49
|
+
value: currentBlock,
|
|
50
|
+
type: "comment-double"
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else if (nextNValue(2) == '//') {
|
|
54
|
+
currentBlock = '';
|
|
55
|
+
|
|
56
|
+
while (currentChar != '\n' && currentChar != null) {
|
|
57
|
+
currentBlock += currentChar;
|
|
58
|
+
next();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
blocks.push({
|
|
62
|
+
value: currentBlock,
|
|
63
|
+
type: "comment-single"
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
else if (currentChar == '}') {
|
|
68
|
+
|
|
69
|
+
blocks.push({
|
|
70
|
+
value: "}",
|
|
71
|
+
type: "end"
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
next();
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
|
|
79
|
+
currentBlock = '';
|
|
80
|
+
while (currentChar != '{' && currentChar != ';' && currentChar != null) {
|
|
81
|
+
currentBlock += currentChar;
|
|
82
|
+
next();
|
|
83
|
+
}
|
|
84
|
+
if (currentChar == null) {
|
|
85
|
+
throw new Error('Statement or code block missing closure.');
|
|
86
|
+
}
|
|
87
|
+
blocks.push({
|
|
88
|
+
value: currentBlock + currentChar,
|
|
89
|
+
type: {
|
|
90
|
+
'{': "begin",
|
|
91
|
+
';': 'statement'
|
|
92
|
+
}[currentChar]
|
|
93
|
+
});
|
|
94
|
+
next();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return blocks;
|
|
98
|
+
};
|
|
99
|
+
module.exports = function (source) {
|
|
100
|
+
this.setFileType("application/javascript");
|
|
101
|
+
let blocks = analyseBlock(source + "");
|
|
102
|
+
let i, j, cssCode = "", preSelectorArray = [], deep = 0;
|
|
103
|
+
for (i = 0; i < blocks.length; i++) {
|
|
104
|
+
if (blocks[i].type == 'comment-double') {
|
|
105
|
+
cssCode += blocks[i].value;
|
|
106
|
+
}
|
|
107
|
+
else if (blocks[i].type == 'comment-single') {
|
|
108
|
+
cssCode += "\n/* " + blocks[i].value + " */\n";
|
|
109
|
+
}
|
|
110
|
+
else if (blocks[i].type == 'begin') {
|
|
111
|
+
let preSplit = blocks[i].value.split(',');
|
|
112
|
+
let preSelect = [];
|
|
113
|
+
for (j = 0; j < preSplit.length; j++) {
|
|
114
|
+
preSelect[j] = preSplit[j].replace(/\{$/, '').trim();
|
|
115
|
+
if (/^&/.test(preSelect[j])) {
|
|
116
|
+
preSelect[j] = preSelect[j].replace(/^&/, '');
|
|
117
|
+
} else {
|
|
118
|
+
preSelect[j] = " " + preSelect[j];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
preSelectorArray[deep] = preSelect;
|
|
122
|
+
deep += 1;
|
|
123
|
+
}
|
|
124
|
+
else if (blocks[i].type == 'end') {
|
|
125
|
+
deep -= 1;
|
|
126
|
+
}
|
|
127
|
+
else if (blocks[i].type == 'statement') {
|
|
128
|
+
j = 1;
|
|
129
|
+
let preType = blocks[i - j].type;
|
|
130
|
+
while (['comment-double', 'comment-single'].indexOf(preType) > -1) {
|
|
131
|
+
j += 1;
|
|
132
|
+
preType = blocks[i - j].type;
|
|
133
|
+
}
|
|
134
|
+
if (['end', 'begin'].indexOf(preType) > -1) {
|
|
135
|
+
cssCode += toSelector(preSelectorArray, deep);
|
|
136
|
+
}
|
|
137
|
+
cssCode += "\n" + blocks[i].value + "\n";
|
|
138
|
+
j = 1;
|
|
139
|
+
let nextType = blocks[i + j].type;
|
|
140
|
+
while (['comment-double', 'comment-single'].indexOf(nextType) > -1) {
|
|
141
|
+
j += 1;
|
|
142
|
+
nextType = blocks[i + j].type;
|
|
143
|
+
}
|
|
144
|
+
if (['end', 'begin'].indexOf(nextType) > -1) {
|
|
145
|
+
cssCode += "\n}\n";
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return `export default ${JSON.stringify(cssCode)}`;
|
|
150
150
|
};
|
package/docs/config.md
CHANGED
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
# 可配置项
|
|
2
|
-
|
|
3
|
-
## name
|
|
4
|
-
|
|
5
|
-
服务器名称,默认OIPage。
|
|
6
|
-
|
|
7
|
-
## version
|
|
8
|
-
|
|
9
|
-
服务器版本,默认使用@oipage/cli版本。
|
|
10
|
-
|
|
11
|
-
## devServer
|
|
12
|
-
|
|
13
|
-
### open
|
|
14
|
-
|
|
15
|
-
是否自动打开浏览器,默认false,true表示打开;也可以是一段地址,比如设置open=“docs/index.html”。
|
|
16
|
-
|
|
17
|
-
### cache
|
|
18
|
-
|
|
19
|
-
是否开启304缓存,默认true,表示开启。
|
|
20
|
-
|
|
21
|
-
### gzip
|
|
22
|
-
|
|
23
|
-
> 始于 v0.3.0
|
|
24
|
-
|
|
25
|
-
是否开启 gzip 压缩,默认true,表示开启。
|
|
26
|
-
|
|
27
|
-
开启后,服务器会对支持 gzip 的客户端请求,自动压缩可压缩类型的文本资源(如 HTML、CSS、JS、JSON、SVG 等),可以有效减少传输体积,加快页面加载速度。
|
|
28
|
-
|
|
29
|
-
使用 Node.js 内置 `zlib` 模块实现,无需安装额外依赖。可通过命令行参数控制:
|
|
30
|
-
|
|
31
|
-
```shell
|
|
32
|
-
oipage-cli serve --gzip true
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
或在配置文件中开启:
|
|
36
|
-
|
|
37
|
-
```js
|
|
38
|
-
devServer: {
|
|
39
|
-
gzip: true
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### port
|
|
44
|
-
|
|
45
|
-
端口,默认8080。此外,可以在执行的时候,通过命令参数覆盖(下同):
|
|
46
|
-
|
|
47
|
-
```shell
|
|
48
|
-
oipage-cli serve --config ./oipage.config.js -p 20000
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### baseUrl
|
|
52
|
-
|
|
53
|
-
服务器根目录,默认当前命令行目录。可以是绝对路径,如果为相对路径,则是相对当前命令行目录。
|
|
54
|
-
|
|
55
|
-
### 404
|
|
56
|
-
|
|
57
|
-
自定义 404 页面,函数接收两个参数 filePath(文件磁盘路径) 和 url(请求地址)。
|
|
58
|
-
|
|
59
|
-
```js
|
|
60
|
-
404: function (filePath, url) {
|
|
61
|
-
return "<h1>自定义的 404 页面</h1><p>你访问的页面不存在!</p>";
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### proxy
|
|
66
|
-
|
|
67
|
-
转发功能
|
|
68
|
-
|
|
69
|
-
```js
|
|
70
|
-
proxy: {
|
|
71
|
-
"/apidemo": {
|
|
72
|
-
target: "https://oi-contrib.github.io/OIPage",
|
|
73
|
-
pathRewrite: { '^/apidemo': '' }, // 地址重写,可选
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### intercept
|
|
79
|
-
|
|
80
|
-
请求拦截,可以实现针对特殊请求的自定义处理。
|
|
81
|
-
|
|
82
|
-
```js
|
|
83
|
-
intercept: Array<{
|
|
84
|
-
test: /\.do$/,
|
|
85
|
-
handler(request, response) {
|
|
86
|
-
// todo
|
|
87
|
-
}
|
|
88
|
-
}>
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
## module
|
|
92
|
-
|
|
93
|
-
### rules
|
|
94
|
-
|
|
95
|
-
用于处理特殊文件,其中use的参数source为原始内容,此函数返回处理后的内容。此外,此函数的this包含若干有用属性或方法,具体如下:
|
|
96
|
-
|
|
97
|
-
- root: 字符串,服务器根路径。
|
|
98
|
-
|
|
99
|
-
- setFileType: 函数,用于设置文件类型。比如如果希望设置为js文件:
|
|
100
|
-
|
|
101
|
-
```js
|
|
102
|
-
this.setFileType("application/javascript")
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
- path: 字符串,文件相对路径。
|
|
106
|
-
|
|
1
|
+
# 可配置项
|
|
2
|
+
|
|
3
|
+
## name
|
|
4
|
+
|
|
5
|
+
服务器名称,默认OIPage。
|
|
6
|
+
|
|
7
|
+
## version
|
|
8
|
+
|
|
9
|
+
服务器版本,默认使用@oipage/cli版本。
|
|
10
|
+
|
|
11
|
+
## devServer
|
|
12
|
+
|
|
13
|
+
### open
|
|
14
|
+
|
|
15
|
+
是否自动打开浏览器,默认false,true表示打开;也可以是一段地址,比如设置open=“docs/index.html”。
|
|
16
|
+
|
|
17
|
+
### cache
|
|
18
|
+
|
|
19
|
+
是否开启304缓存,默认true,表示开启。
|
|
20
|
+
|
|
21
|
+
### gzip
|
|
22
|
+
|
|
23
|
+
> 始于 v0.3.0
|
|
24
|
+
|
|
25
|
+
是否开启 gzip 压缩,默认true,表示开启。
|
|
26
|
+
|
|
27
|
+
开启后,服务器会对支持 gzip 的客户端请求,自动压缩可压缩类型的文本资源(如 HTML、CSS、JS、JSON、SVG 等),可以有效减少传输体积,加快页面加载速度。
|
|
28
|
+
|
|
29
|
+
使用 Node.js 内置 `zlib` 模块实现,无需安装额外依赖。可通过命令行参数控制:
|
|
30
|
+
|
|
31
|
+
```shell
|
|
32
|
+
oipage-cli serve --gzip true
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
或在配置文件中开启:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
devServer: {
|
|
39
|
+
gzip: true
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### port
|
|
44
|
+
|
|
45
|
+
端口,默认8080。此外,可以在执行的时候,通过命令参数覆盖(下同):
|
|
46
|
+
|
|
47
|
+
```shell
|
|
48
|
+
oipage-cli serve --config ./oipage.config.js -p 20000
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### baseUrl
|
|
52
|
+
|
|
53
|
+
服务器根目录,默认当前命令行目录。可以是绝对路径,如果为相对路径,则是相对当前命令行目录。
|
|
54
|
+
|
|
55
|
+
### 404
|
|
56
|
+
|
|
57
|
+
自定义 404 页面,函数接收两个参数 filePath(文件磁盘路径) 和 url(请求地址)。
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
404: function (filePath, url) {
|
|
61
|
+
return "<h1>自定义的 404 页面</h1><p>你访问的页面不存在!</p>";
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### proxy
|
|
66
|
+
|
|
67
|
+
转发功能
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
proxy: {
|
|
71
|
+
"/apidemo": {
|
|
72
|
+
target: "https://oi-contrib.github.io/OIPage",
|
|
73
|
+
pathRewrite: { '^/apidemo': '' }, // 地址重写,可选
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### intercept
|
|
79
|
+
|
|
80
|
+
请求拦截,可以实现针对特殊请求的自定义处理。
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
intercept: Array<{
|
|
84
|
+
test: /\.do$/,
|
|
85
|
+
handler(request, response) {
|
|
86
|
+
// todo
|
|
87
|
+
}
|
|
88
|
+
}>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## module
|
|
92
|
+
|
|
93
|
+
### rules
|
|
94
|
+
|
|
95
|
+
用于处理特殊文件,其中use的参数source为原始内容,此函数返回处理后的内容。此外,此函数的this包含若干有用属性或方法,具体如下:
|
|
96
|
+
|
|
97
|
+
- root: 字符串,服务器根路径。
|
|
98
|
+
|
|
99
|
+
- setFileType: 函数,用于设置文件类型。比如如果希望设置为js文件:
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
this.setFileType("application/javascript")
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
- path: 字符串,文件相对路径。
|
|
106
|
+
|
|
107
107
|
- entry: 布尔值,是否是浏览器地址栏直接访问。
|
package/package.json
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@oipage/cli",
|
|
3
|
-
"version": "0.3.0
|
|
4
|
-
"description": "开发快速助手,一个包含常用功能的命令行工具,旨在提升开发效率",
|
|
5
|
-
"sideEffects": false,
|
|
6
|
-
"main": "./src/index.js",
|
|
7
|
-
"typings": "./types/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"serve": "node ./bin/run serve --config ./oipage.config.js"
|
|
10
|
-
},
|
|
11
|
-
"bin": {
|
|
12
|
-
"oipage-cli": "bin/run"
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/oi-contrib/oipage-cli.git"
|
|
17
|
-
},
|
|
18
|
-
"keywords": [
|
|
19
|
-
"dev",
|
|
20
|
-
"server",
|
|
21
|
-
"style",
|
|
22
|
-
"css",
|
|
23
|
-
"nodejs",
|
|
24
|
-
"core",
|
|
25
|
-
"oipage",
|
|
26
|
-
"browser"
|
|
27
|
-
],
|
|
28
|
-
"author": {
|
|
29
|
-
"name": "zxl20070701",
|
|
30
|
-
"url": "https://zxl20070701.github.io/notebook/home.html"
|
|
31
|
-
},
|
|
32
|
-
"license": "MIT",
|
|
33
|
-
"bugs": {
|
|
34
|
-
"url": "https://github.com/oi-contrib/oipage-cli/issues"
|
|
35
|
-
},
|
|
36
|
-
"homepage": "https://github.com/oi-contrib/oipage-cli",
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"oipage": "^2.0.0",
|
|
39
|
-
"vislite": "^1.9.1",
|
|
40
|
-
"xhtml-to-json": "^0.2.1",
|
|
41
|
-
"zipaper": "^0.4.0"
|
|
42
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@oipage/cli",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "开发快速助手,一个包含常用功能的命令行工具,旨在提升开发效率",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"typings": "./types/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"serve": "node ./bin/run serve --config ./oipage.config.js"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"oipage-cli": "bin/run"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/oi-contrib/oipage-cli.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"dev",
|
|
20
|
+
"server",
|
|
21
|
+
"style",
|
|
22
|
+
"css",
|
|
23
|
+
"nodejs",
|
|
24
|
+
"core",
|
|
25
|
+
"oipage",
|
|
26
|
+
"browser"
|
|
27
|
+
],
|
|
28
|
+
"author": {
|
|
29
|
+
"name": "zxl20070701",
|
|
30
|
+
"url": "https://zxl20070701.github.io/notebook/home.html"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/oi-contrib/oipage-cli/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/oi-contrib/oipage-cli",
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"oipage": "^2.0.0",
|
|
39
|
+
"vislite": "^1.9.1",
|
|
40
|
+
"xhtml-to-json": "^0.2.1",
|
|
41
|
+
"zipaper": "^0.4.0"
|
|
42
|
+
}
|
|
43
43
|
}
|
package/src/index.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
const { mergeOption } = require("oipage/nodejs/option/index");
|
|
2
|
-
|
|
3
|
-
// 开发服务器
|
|
4
|
-
exports.serve = function (config) {
|
|
5
|
-
let option = {
|
|
6
|
-
devServer: {
|
|
7
|
-
port: 8080,
|
|
8
|
-
baseUrl: "./",
|
|
9
|
-
open: false,
|
|
10
|
-
cache: true,
|
|
11
|
-
gzip: true,
|
|
12
|
-
proxy: {},
|
|
13
|
-
intercept: [],
|
|
14
|
-
404: null,
|
|
15
|
-
website: false
|
|
16
|
-
},
|
|
17
|
-
module: {
|
|
18
|
-
rules: []
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
mergeOption(option, config);
|
|
23
|
-
require("../bin/serve")(option);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
exports.ZipaperIntercept = require("../bin/website-plugins/intercept/oipage-zipaper-intercept.js");
|
|
27
|
-
exports.VISLiteIntercept = require("../bin/website-plugins/intercept/oipage-vislite-intercept.js");
|
|
28
|
-
|
|
29
|
-
exports.ScssLoader = require("../bin/website-plugins/loader/oipage-scss-loader.js");
|
|
1
|
+
const { mergeOption } = require("oipage/nodejs/option/index");
|
|
2
|
+
|
|
3
|
+
// 开发服务器
|
|
4
|
+
exports.serve = function (config) {
|
|
5
|
+
let option = {
|
|
6
|
+
devServer: {
|
|
7
|
+
port: 8080,
|
|
8
|
+
baseUrl: "./",
|
|
9
|
+
open: false,
|
|
10
|
+
cache: true,
|
|
11
|
+
gzip: true,
|
|
12
|
+
proxy: {},
|
|
13
|
+
intercept: [],
|
|
14
|
+
404: null,
|
|
15
|
+
website: false
|
|
16
|
+
},
|
|
17
|
+
module: {
|
|
18
|
+
rules: []
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
mergeOption(option, config);
|
|
23
|
+
require("../bin/serve")(option);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
exports.ZipaperIntercept = require("../bin/website-plugins/intercept/oipage-zipaper-intercept.js");
|
|
27
|
+
exports.VISLiteIntercept = require("../bin/website-plugins/intercept/oipage-vislite-intercept.js");
|
|
28
|
+
|
|
29
|
+
exports.ScssLoader = require("../bin/website-plugins/loader/oipage-scss-loader.js");
|
|
30
30
|
exports.HtmlLoader = require("../bin/website-plugins/loader/oipage-html-loader.js");
|