@m00rl0ck/simple-builder 1.0.1 → 1.0.3
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/bin/cli.js +5 -1
- package/dev-server.js +17 -4
- package/index.js +1 -5
- package/package.json +2 -2
- package/minify.js +0 -135
package/bin/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { build } from '../
|
|
3
|
+
import { build, runServer } from '../dev-server.js';
|
|
4
4
|
|
|
5
5
|
const args = process.argv.slice(2);
|
|
6
6
|
|
|
@@ -11,3 +11,7 @@ if (args.includes('build')) {
|
|
|
11
11
|
if (args.includes('dev')) {
|
|
12
12
|
build({ watch: true });
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
if (args.includes('serve')) {
|
|
16
|
+
runServer();
|
|
17
|
+
}
|
package/dev-server.js
CHANGED
|
@@ -111,6 +111,17 @@ function watch() {
|
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
// ======================
|
|
115
|
+
// 👀 BUILD
|
|
116
|
+
// ======================
|
|
117
|
+
export function build({ watch }) {
|
|
118
|
+
if (!!watch) {
|
|
119
|
+
return watch();
|
|
120
|
+
} else {
|
|
121
|
+
return build();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
114
125
|
// ======================
|
|
115
126
|
// 🚀 SERVER
|
|
116
127
|
// ======================
|
|
@@ -127,8 +138,10 @@ const server = http.createServer((req, res) => {
|
|
|
127
138
|
// ▶️ START
|
|
128
139
|
// ======================
|
|
129
140
|
|
|
130
|
-
|
|
141
|
+
export function renServer() {
|
|
142
|
+
watch();
|
|
131
143
|
|
|
132
|
-
server.listen(PORT, () => {
|
|
133
|
-
|
|
134
|
-
});
|
|
144
|
+
server.listen(PORT, () => {
|
|
145
|
+
console.log(`\n🚀 Dev server running: http://localhost:${PORT}\n`);
|
|
146
|
+
});
|
|
147
|
+
}
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m00rl0ck/simple-builder",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Zero-dependency JS bundler with dev server and minifier",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Zero-dependency JS and CSS bundler with dev server and minifier",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"bin": {
|
package/minify.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
export function minifyJS(code) {
|
|
2
|
-
let out = '';
|
|
3
|
-
let i = 0;
|
|
4
|
-
|
|
5
|
-
let inString = false;
|
|
6
|
-
let stringChar = '';
|
|
7
|
-
let inTemplate = false;
|
|
8
|
-
let inRegex = false;
|
|
9
|
-
let inSingleComment = false;
|
|
10
|
-
let inMultiComment = false;
|
|
11
|
-
|
|
12
|
-
while (i < code.length) {
|
|
13
|
-
const c = code[i];
|
|
14
|
-
const next = code[i + 1];
|
|
15
|
-
|
|
16
|
-
// ======================
|
|
17
|
-
// COMMENTS
|
|
18
|
-
// ======================
|
|
19
|
-
|
|
20
|
-
if (inSingleComment) {
|
|
21
|
-
if (c === '\n') {
|
|
22
|
-
inSingleComment = false;
|
|
23
|
-
}
|
|
24
|
-
i++;
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (inMultiComment) {
|
|
29
|
-
if (c === '*' && next === '/') {
|
|
30
|
-
inMultiComment = false;
|
|
31
|
-
i += 2;
|
|
32
|
-
} else {
|
|
33
|
-
i++;
|
|
34
|
-
}
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (!inString && !inTemplate && !inRegex) {
|
|
39
|
-
if (c === '/' && next === '/') {
|
|
40
|
-
inSingleComment = true;
|
|
41
|
-
i += 2;
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (c === '/' && next === '*') {
|
|
46
|
-
inMultiComment = true;
|
|
47
|
-
i += 2;
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// ======================
|
|
53
|
-
// STRINGS
|
|
54
|
-
// ======================
|
|
55
|
-
|
|
56
|
-
if (!inTemplate && !inRegex && (c === '"' || c === "'")) {
|
|
57
|
-
if (inString && c === stringChar && code[i - 1] !== '\\') {
|
|
58
|
-
inString = false;
|
|
59
|
-
} else if (!inString) {
|
|
60
|
-
inString = true;
|
|
61
|
-
stringChar = c;
|
|
62
|
-
}
|
|
63
|
-
out += c;
|
|
64
|
-
i++;
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// ======================
|
|
69
|
-
// TEMPLATE
|
|
70
|
-
// ======================
|
|
71
|
-
|
|
72
|
-
if (!inString && !inRegex && c === '`') {
|
|
73
|
-
inTemplate = !inTemplate;
|
|
74
|
-
out += c;
|
|
75
|
-
i++;
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// ======================
|
|
80
|
-
// REGEX (simplified)
|
|
81
|
-
// ======================
|
|
82
|
-
|
|
83
|
-
if (!inString && !inTemplate && c === '/' && !inRegex) {
|
|
84
|
-
// naive check: після ( або = або : або , → regex
|
|
85
|
-
const prev = out.trim().slice(-1);
|
|
86
|
-
if (!prev || '({[=,:;!&|?'.includes(prev)) {
|
|
87
|
-
inRegex = true;
|
|
88
|
-
out += c;
|
|
89
|
-
i++;
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (inRegex) {
|
|
95
|
-
if (c === '/' && code[i - 1] !== '\\') {
|
|
96
|
-
inRegex = false;
|
|
97
|
-
}
|
|
98
|
-
out += c;
|
|
99
|
-
i++;
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// ======================
|
|
104
|
-
// WHITESPACE
|
|
105
|
-
// ======================
|
|
106
|
-
|
|
107
|
-
if (!inString && !inTemplate && !inRegex) {
|
|
108
|
-
if (/\s/.test(c)) {
|
|
109
|
-
const prev = out[out.length - 1];
|
|
110
|
-
const nextChar = code[i + 1];
|
|
111
|
-
|
|
112
|
-
// не додаємо зайві пробіли
|
|
113
|
-
if (
|
|
114
|
-
prev &&
|
|
115
|
-
/[a-zA-Z0-9_$]/.test(prev) &&
|
|
116
|
-
/[a-zA-Z0-9_$]/.test(nextChar)
|
|
117
|
-
) {
|
|
118
|
-
out += ' ';
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
i++;
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// ======================
|
|
127
|
-
// DEFAULT
|
|
128
|
-
// ======================
|
|
129
|
-
|
|
130
|
-
out += c;
|
|
131
|
-
i++;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return out.trim();
|
|
135
|
-
}
|