neactor-cli 1.0.3 → 1.0.4
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/build.js +6 -4
- package/cli.js +3 -3
- package/dev.js +26 -12
- package/jsx-shim.js +3 -0
- package/package.json +1 -1
- package/preview.js +27 -10
package/build.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import * as esbuild from "esbuild";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import crypto from "crypto";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
|
|
7
|
+
const jsxShimPath = fileURLToPath(new URL("./jsx-shim.js", import.meta.url));
|
|
5
8
|
|
|
6
9
|
export const build = async () => {
|
|
7
10
|
// 1. Bundle JS
|
|
@@ -14,9 +17,7 @@ export const build = async () => {
|
|
|
14
17
|
jsx: "transform",
|
|
15
18
|
jsxFactory: "neactorCreateElement",
|
|
16
19
|
jsxImportSource: "neactor-dom",
|
|
17
|
-
|
|
18
|
-
js: `import { createElement } from 'neactor-dom';`,
|
|
19
|
-
},
|
|
20
|
+
inject: [jsxShimPath],
|
|
20
21
|
entryNames: "bundle",
|
|
21
22
|
write: true,
|
|
22
23
|
metafile: true,
|
|
@@ -29,8 +30,9 @@ export const build = async () => {
|
|
|
29
30
|
let html = fs.readFileSync("index.html", "utf8");
|
|
30
31
|
html = html.replace(
|
|
31
32
|
/<script type="module" src="[^"]+"><\/script>/,
|
|
32
|
-
`<script src="./bundle.js"></script>`,
|
|
33
|
+
`<script type="module" src="./bundle.js"></script>`,
|
|
33
34
|
);
|
|
35
|
+
|
|
34
36
|
fs.mkdirSync("dist", { recursive: true });
|
|
35
37
|
fs.writeFileSync("dist/index.html", html);
|
|
36
38
|
};
|
package/cli.js
CHANGED
|
@@ -14,8 +14,8 @@ if (command === "dev") {
|
|
|
14
14
|
} else {
|
|
15
15
|
console.log(`
|
|
16
16
|
Usage:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
neactor dev start dev server
|
|
18
|
+
neactor build production build
|
|
19
|
+
neactor preview preview production build
|
|
20
20
|
`);
|
|
21
21
|
}
|
package/dev.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as esbuild from "esbuild";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import http from "http";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
|
|
7
|
+
const jsxShimPath = fileURLToPath(new URL("./jsx-shim.js", import.meta.url));
|
|
4
8
|
|
|
5
9
|
export const dev = async () => {
|
|
6
10
|
const clients = new Set();
|
|
@@ -14,15 +18,13 @@ export const dev = async () => {
|
|
|
14
18
|
jsx: "transform",
|
|
15
19
|
jsxFactory: "neactorCreateElement",
|
|
16
20
|
jsxImportSource: "neactor-dom",
|
|
17
|
-
|
|
18
|
-
js: `import { createElement } from 'neactor-dom';`,
|
|
19
|
-
},
|
|
21
|
+
inject: [jsxShimPath],
|
|
20
22
|
plugins: [
|
|
21
23
|
{
|
|
22
24
|
name: "live-reload",
|
|
23
25
|
setup(build) {
|
|
24
26
|
build.onEnd(() => {
|
|
25
|
-
clients.forEach((res) => res.write("data: reload
|
|
27
|
+
clients.forEach((res) => res.write("data: reload\\n\\n"));
|
|
26
28
|
});
|
|
27
29
|
},
|
|
28
30
|
},
|
|
@@ -33,13 +35,20 @@ export const dev = async () => {
|
|
|
33
35
|
|
|
34
36
|
let html = fs.readFileSync("index.html", "utf8");
|
|
35
37
|
html = html.replace(
|
|
36
|
-
/<script src="[^"]+"><\/script>/,
|
|
37
|
-
`<script src="./main.js"></script>`,
|
|
38
|
+
/<script type="module" src="[^"]+"><\/script>/,
|
|
39
|
+
`<script type="module" src="./main.js"></script>`,
|
|
38
40
|
);
|
|
39
41
|
fs.mkdirSync("dist", { recursive: true });
|
|
40
42
|
fs.writeFileSync("dist/index.html", html);
|
|
41
43
|
|
|
42
|
-
|
|
44
|
+
const mimeTypes = {
|
|
45
|
+
".html": "text/html; charset=utf-8",
|
|
46
|
+
".js": "application/javascript; charset=utf-8",
|
|
47
|
+
".map": "application/json; charset=utf-8",
|
|
48
|
+
".css": "text/css; charset=utf-8",
|
|
49
|
+
".json": "application/json; charset=utf-8",
|
|
50
|
+
};
|
|
51
|
+
|
|
43
52
|
http
|
|
44
53
|
.createServer((req, res) => {
|
|
45
54
|
if (req.url === "/__reload") {
|
|
@@ -53,15 +62,20 @@ export const dev = async () => {
|
|
|
53
62
|
return;
|
|
54
63
|
}
|
|
55
64
|
|
|
56
|
-
|
|
57
|
-
const filePath =
|
|
65
|
+
const requestPath = req.url === "/" ? "/index.html" : req.url;
|
|
66
|
+
const filePath = path.join("dist", requestPath);
|
|
67
|
+
|
|
58
68
|
fs.readFile(filePath, (err, data) => {
|
|
59
69
|
if (err) {
|
|
60
|
-
res.writeHead(404);
|
|
61
|
-
res.end();
|
|
70
|
+
res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
|
|
71
|
+
res.end("Not Found");
|
|
62
72
|
return;
|
|
63
73
|
}
|
|
64
|
-
|
|
74
|
+
|
|
75
|
+
const ext = path.extname(filePath);
|
|
76
|
+
res.writeHead(200, {
|
|
77
|
+
"Content-Type": mimeTypes[ext] || "application/octet-stream",
|
|
78
|
+
});
|
|
65
79
|
res.end(data);
|
|
66
80
|
});
|
|
67
81
|
})
|
package/jsx-shim.js
ADDED
package/package.json
CHANGED
package/preview.js
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import { createServer } from "http";
|
|
2
|
-
import
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
const mimeTypes = {
|
|
6
|
+
".html": "text/html; charset=utf-8",
|
|
7
|
+
".js": "application/javascript; charset=utf-8",
|
|
8
|
+
".css": "text/css; charset=utf-8",
|
|
9
|
+
".json": "application/json; charset=utf-8",
|
|
10
|
+
".map": "application/json; charset=utf-8",
|
|
11
|
+
};
|
|
3
12
|
|
|
4
13
|
export const preview = async () => {
|
|
5
|
-
createServer(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
createServer((req, res) => {
|
|
15
|
+
const requestPath = req.url === "/" ? "/index.html" : req.url;
|
|
16
|
+
const filePath = path.join("dist", requestPath);
|
|
17
|
+
|
|
18
|
+
fs.readFile(filePath, (err, data) => {
|
|
19
|
+
if (err) {
|
|
20
|
+
res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
|
|
21
|
+
res.end("Not Found");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const ext = path.extname(filePath);
|
|
26
|
+
res.writeHead(200, {
|
|
27
|
+
"Content-Type": mimeTypes[ext] || "application/octet-stream",
|
|
28
|
+
});
|
|
29
|
+
res.end(data);
|
|
30
|
+
});
|
|
14
31
|
}).listen(4000, () => console.log("prod server is running on port: 4000"));
|
|
15
32
|
};
|