vite-plugin-spire.officejs-test 1.0.10 → 1.0.11
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/lib/index.mjs +12 -9
- package/lib/utils/initserver.mjs +27 -27
- package/package.json +1 -1
package/lib/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { fileURLToPath as
|
|
1
|
+
import { fileURLToPath as t } from "node:url";
|
|
2
2
|
import { dirname as a } from "node:path";
|
|
3
3
|
import c from "path";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
a(
|
|
7
|
-
function v(
|
|
4
|
+
import n from "./utils/initserver.mjs";
|
|
5
|
+
import f from "./utils/bundle.mjs";
|
|
6
|
+
a(t(import.meta.url));
|
|
7
|
+
function v(p = {}) {
|
|
8
8
|
const i = [
|
|
9
9
|
{
|
|
10
10
|
package: "spire.officejs-web-word",
|
|
@@ -62,7 +62,10 @@ function v(s = {}) {
|
|
|
62
62
|
name: "fontsweb",
|
|
63
63
|
build: "/fontsweb"
|
|
64
64
|
}
|
|
65
|
-
], {
|
|
65
|
+
], {
|
|
66
|
+
port: s = 7e3,
|
|
67
|
+
name: o = "vite-plugin-spire.officejs"
|
|
68
|
+
} = p;
|
|
66
69
|
let r = "";
|
|
67
70
|
return {
|
|
68
71
|
name: o,
|
|
@@ -72,12 +75,12 @@ function v(s = {}) {
|
|
|
72
75
|
// 开发环境
|
|
73
76
|
// 创建一个子进程来提供officeJS的静态资源
|
|
74
77
|
configureServer(e) {
|
|
75
|
-
|
|
78
|
+
n(e, i, s, o);
|
|
76
79
|
},
|
|
77
80
|
// 生产环境
|
|
78
81
|
// 将officeJS的静态资源拷贝到输出目录中
|
|
79
|
-
async writeBundle(e,
|
|
80
|
-
|
|
82
|
+
async writeBundle(e, m) {
|
|
83
|
+
await f(e, r, i);
|
|
81
84
|
}
|
|
82
85
|
};
|
|
83
86
|
}
|
package/lib/utils/initserver.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { createServer as
|
|
2
|
-
import { fileURLToPath as
|
|
3
|
-
import { dirname as
|
|
4
|
-
import { access as
|
|
5
|
-
import { statSync as
|
|
1
|
+
import { createServer as j } from "node:http";
|
|
2
|
+
import { fileURLToPath as x } from "node:url";
|
|
3
|
+
import { dirname as y, resolve as P, join as k } from "node:path";
|
|
4
|
+
import { access as S } from "node:fs/promises";
|
|
5
|
+
import { statSync as C, createReadStream as H } from "node:fs";
|
|
6
6
|
const A = (f, i, c, g) => {
|
|
7
7
|
var p;
|
|
8
|
-
let
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
const l = new URL(
|
|
12
|
-
let
|
|
13
|
-
if (l.includes("Spire.Pdf.Base") ?
|
|
8
|
+
let r;
|
|
9
|
+
r = j(async (o, t) => {
|
|
10
|
+
var m;
|
|
11
|
+
const l = new URL(o.url, `http://${o.headers.host}`).pathname;
|
|
12
|
+
let a = {};
|
|
13
|
+
if (l.includes("Spire.Pdf.Base") ? a = i.find((e) => e.name == "pdf") : a = i.find((e) => l.startsWith(e.route)), !a) {
|
|
14
14
|
t.writeHead(404, { "Content-Type": "text/plain" }), t.end("Resource not found");
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
@@ -18,15 +18,15 @@ const A = (f, i, c, g) => {
|
|
|
18
18
|
try {
|
|
19
19
|
let e;
|
|
20
20
|
try {
|
|
21
|
-
const s = await import.meta.resolve(`${
|
|
22
|
-
e =
|
|
21
|
+
const s = await import.meta.resolve(`${a.package}/package.json`);
|
|
22
|
+
e = y(s);
|
|
23
23
|
} catch {
|
|
24
|
-
e =
|
|
24
|
+
e = P(process.cwd(), "node_modules", a.package);
|
|
25
25
|
}
|
|
26
26
|
e.startsWith("file://") || (e.startsWith("/") || e.match(/^[A-Za-z]:/)) && (e = "file://" + (e.startsWith("/") ? "" : "/") + e);
|
|
27
|
-
const u =
|
|
28
|
-
|
|
29
|
-
const
|
|
27
|
+
const u = x(e), w = l.replace(a.route, "") || "/index.html", n = k(u, a.path, w);
|
|
28
|
+
await S(n);
|
|
29
|
+
const v = C(n), h = (m = n.split(".").pop()) == null ? void 0 : m.toLowerCase(), $ = {
|
|
30
30
|
html: "text/html",
|
|
31
31
|
js: "application/javascript",
|
|
32
32
|
css: "text/css",
|
|
@@ -37,22 +37,22 @@ const A = (f, i, c, g) => {
|
|
|
37
37
|
wasm: "application/wasm"
|
|
38
38
|
};
|
|
39
39
|
t.writeHead(200, {
|
|
40
|
-
"Content-Type":
|
|
41
|
-
"Content-Length":
|
|
40
|
+
"Content-Type": h && $[h] || "application/octet-stream",
|
|
41
|
+
"Content-Length": v.size
|
|
42
42
|
});
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
console.error(`Stream error for ${
|
|
43
|
+
const d = H(n);
|
|
44
|
+
d.pipe(t), d.on("error", (s) => {
|
|
45
|
+
console.error(`Stream error for ${n}:`, s), t.writeHead(500), t.end("Internal server error");
|
|
46
46
|
});
|
|
47
47
|
} catch (e) {
|
|
48
|
-
e.code === "ENOENT" ? (t.writeHead(404, { "Content-Type": "text/plain" }), t.end(`File not found: ${
|
|
48
|
+
e.code === "ENOENT" ? (t.writeHead(404, { "Content-Type": "text/plain" }), t.end(`File not found: ${o.url}`)) : (console.error(`Error serving ${o.url}:`, e), t.writeHead(500), t.end("Internal server error"));
|
|
49
49
|
}
|
|
50
|
-
}),
|
|
51
|
-
console.log(`📦 [${g}]
|
|
52
|
-
console.log(` -
|
|
50
|
+
}), r.listen(c, () => {
|
|
51
|
+
console.log(`📦 [${g}] spire.officejs静态资源服务已启动:`), console.log(` - 服务地址: http://localhost:${c}`), i.forEach((o) => {
|
|
52
|
+
console.log(` - 映射 ${o.package}${o.path} -> http://localhost:${c}${o.route}`);
|
|
53
53
|
});
|
|
54
54
|
}), (p = f.httpServer) == null || p.on("close", () => {
|
|
55
|
-
|
|
55
|
+
r == null || r.close();
|
|
56
56
|
});
|
|
57
57
|
};
|
|
58
58
|
export {
|