@xfe-repo/web-app 1.6.4 → 2.0.0-beta.2
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/README.md +118 -1
- package/client.d.ts +1 -0
- package/deploy/.drone.yml +13 -4
- package/deploy/Dockerfile +15 -6
- package/deploy/helm/templates/deployment.yaml +5 -18
- package/deploy/helm/templates/svc.yaml +1 -1
- package/dist/cli.js +577 -416
- package/dist/cli.mjs +562 -256
- package/dist/config.d.mts +30 -6
- package/dist/config.d.ts +30 -6
- package/dist/config.js +142 -298
- package/dist/config.mjs +124 -2
- package/dist/framework.d.mts +10 -0
- package/dist/framework.d.ts +10 -0
- package/dist/framework.js +220 -0
- package/dist/framework.mjs +182 -0
- package/dist/node-dev.d.mts +2 -0
- package/dist/node-dev.d.ts +2 -0
- package/dist/node-dev.js +358 -0
- package/dist/node-dev.mjs +332 -0
- package/dist/node.d.mts +27 -0
- package/dist/node.d.ts +27 -0
- package/dist/node.js +381 -0
- package/dist/node.mjs +343 -0
- package/dist/react-router-config.d.mts +11 -0
- package/dist/react-router-config.d.ts +11 -0
- package/dist/react-router-config.js +111 -0
- package/dist/react-router-config.mjs +77 -0
- package/dist/root.d.mts +17 -0
- package/dist/root.d.ts +17 -0
- package/dist/root.js +61 -0
- package/dist/root.mjs +34 -0
- package/dist/serve.d.mts +10 -0
- package/dist/serve.d.ts +10 -0
- package/dist/serve.js +71 -0
- package/dist/serve.mjs +36 -0
- package/dist/vite.d.mts +10 -0
- package/dist/vite.d.ts +10 -0
- package/dist/vite.js +182 -0
- package/dist/vite.mjs +146 -0
- package/package.json +27 -72
- package/tsconfig.json +4 -1
- package/config/env.js +0 -104
- package/config/getHttpsConfig.js +0 -66
- package/config/jest/babelTransform.js +0 -29
- package/config/jest/cssTransform.js +0 -14
- package/config/jest/fileTransform.js +0 -40
- package/config/modules.js +0 -133
- package/config/paths.js +0 -65
- package/config/webpack/persistentCache/createEnvironmentHash.js +0 -9
- package/config/webpack/webpack.config.js +0 -737
- package/config/webpack/webpackDevServer.config.js +0 -122
- package/deploy/nginx.conf +0 -62
- package/dist/chunk-75BJNL7E.mjs +0 -239
- package/scripts/build.js +0 -217
- package/scripts/dev.js +0 -162
package/dist/root.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/root.tsx
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { Links, Meta, Scripts, ScrollRestoration, useRouteError } from "react-router";
|
|
4
|
+
import { DefaultErrorBoundary } from "@xfe-repo/web-router/errors";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
function PageLoading() {
|
|
7
|
+
return /* @__PURE__ */ jsx("main", { role: "status", "aria-live": "polite", children: "\u6B63\u5728\u52A0\u8F7D\u9875\u9762\u2026" });
|
|
8
|
+
}
|
|
9
|
+
function Document({ children, lang = "zh-CN", themeColor }) {
|
|
10
|
+
return /* @__PURE__ */ jsxs("html", { lang, children: [
|
|
11
|
+
/* @__PURE__ */ jsxs("head", { children: [
|
|
12
|
+
/* @__PURE__ */ jsx("meta", { charSet: "utf-8" }),
|
|
13
|
+
/* @__PURE__ */ jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }),
|
|
14
|
+
themeColor && /* @__PURE__ */ jsx("meta", { name: "theme-color", content: themeColor }),
|
|
15
|
+
/* @__PURE__ */ jsx(Meta, {}),
|
|
16
|
+
/* @__PURE__ */ jsx(Links, {})
|
|
17
|
+
] }),
|
|
18
|
+
/* @__PURE__ */ jsxs("body", { children: [
|
|
19
|
+
/* @__PURE__ */ jsx("noscript", { children: "\u8BF7\u5141\u8BB8 JavaScript \u8FD0\u884C\u3002" }),
|
|
20
|
+
children,
|
|
21
|
+
/* @__PURE__ */ jsx(ScrollRestoration, {}),
|
|
22
|
+
/* @__PURE__ */ jsx(Scripts, {})
|
|
23
|
+
] })
|
|
24
|
+
] });
|
|
25
|
+
}
|
|
26
|
+
function PageError({ view }) {
|
|
27
|
+
const error = useRouteError();
|
|
28
|
+
return view ? createElement(view, { error }) : createElement(DefaultErrorBoundary);
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
Document,
|
|
32
|
+
PageError,
|
|
33
|
+
PageLoading
|
|
34
|
+
};
|
package/dist/serve.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
|
|
3
|
+
declare const serveClient: ({ directory, host, port, basename, }: {
|
|
4
|
+
directory: string;
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
basename?: string;
|
|
8
|
+
}) => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
9
|
+
|
|
10
|
+
export { serveClient };
|
package/dist/serve.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
|
|
3
|
+
declare const serveClient: ({ directory, host, port, basename, }: {
|
|
4
|
+
directory: string;
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
basename?: string;
|
|
8
|
+
}) => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
9
|
+
|
|
10
|
+
export { serveClient };
|
package/dist/serve.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/serve.ts
|
|
31
|
+
var serve_exports = {};
|
|
32
|
+
__export(serve_exports, {
|
|
33
|
+
serveClient: () => serveClient
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(serve_exports);
|
|
36
|
+
var import_node_fs = require("fs");
|
|
37
|
+
var import_node_path = __toESM(require("path"));
|
|
38
|
+
var import_express = __toESM(require("express"));
|
|
39
|
+
var serveClient = ({
|
|
40
|
+
directory,
|
|
41
|
+
host,
|
|
42
|
+
port,
|
|
43
|
+
basename = "/"
|
|
44
|
+
}) => {
|
|
45
|
+
const indexFile = import_node_path.default.join(directory, "index.html");
|
|
46
|
+
if (!(0, import_node_fs.existsSync)(indexFile)) throw new Error(`\u672A\u627E\u5230 SPA \u5165\u53E3 ${indexFile}\uFF0C\u8BF7\u5148\u6267\u884C xfe-web build`);
|
|
47
|
+
const app = (0, import_express.default)().disable("x-powered-by");
|
|
48
|
+
const router = import_express.default.Router();
|
|
49
|
+
app.use((_request, response, next) => {
|
|
50
|
+
response.setHeader("Access-Control-Allow-Origin", "*");
|
|
51
|
+
next();
|
|
52
|
+
});
|
|
53
|
+
app.use(
|
|
54
|
+
"/assets",
|
|
55
|
+
import_express.default.static(import_node_path.default.join(directory, "assets"), { immutable: true, maxAge: "1y" }),
|
|
56
|
+
(_request, response) => response.status(404).end()
|
|
57
|
+
);
|
|
58
|
+
app.use(import_express.default.static(directory));
|
|
59
|
+
router.get("/{*path}", (_request, response) => response.sendFile(indexFile));
|
|
60
|
+
app.use(basename, router);
|
|
61
|
+
const server = app.listen(port, host);
|
|
62
|
+
server.once("listening", () => {
|
|
63
|
+
const address = server.address();
|
|
64
|
+
console.log(`[xfe-web] SPA http://${host}:${typeof address === "object" && address ? address.port : port}${basename}`);
|
|
65
|
+
});
|
|
66
|
+
return server;
|
|
67
|
+
};
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
serveClient
|
|
71
|
+
});
|
package/dist/serve.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/serve.ts
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import express from "express";
|
|
5
|
+
var serveClient = ({
|
|
6
|
+
directory,
|
|
7
|
+
host,
|
|
8
|
+
port,
|
|
9
|
+
basename = "/"
|
|
10
|
+
}) => {
|
|
11
|
+
const indexFile = path.join(directory, "index.html");
|
|
12
|
+
if (!existsSync(indexFile)) throw new Error(`\u672A\u627E\u5230 SPA \u5165\u53E3 ${indexFile}\uFF0C\u8BF7\u5148\u6267\u884C xfe-web build`);
|
|
13
|
+
const app = express().disable("x-powered-by");
|
|
14
|
+
const router = express.Router();
|
|
15
|
+
app.use((_request, response, next) => {
|
|
16
|
+
response.setHeader("Access-Control-Allow-Origin", "*");
|
|
17
|
+
next();
|
|
18
|
+
});
|
|
19
|
+
app.use(
|
|
20
|
+
"/assets",
|
|
21
|
+
express.static(path.join(directory, "assets"), { immutable: true, maxAge: "1y" }),
|
|
22
|
+
(_request, response) => response.status(404).end()
|
|
23
|
+
);
|
|
24
|
+
app.use(express.static(directory));
|
|
25
|
+
router.get("/{*path}", (_request, response) => response.sendFile(indexFile));
|
|
26
|
+
app.use(basename, router);
|
|
27
|
+
const server = app.listen(port, host);
|
|
28
|
+
server.once("listening", () => {
|
|
29
|
+
const address = server.address();
|
|
30
|
+
console.log(`[xfe-web] SPA http://${host}:${typeof address === "object" && address ? address.port : port}${basename}`);
|
|
31
|
+
});
|
|
32
|
+
return server;
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
serveClient
|
|
36
|
+
};
|
package/dist/vite.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as vite from 'vite';
|
|
2
|
+
|
|
3
|
+
declare const adaptPageRoute: (code: string, options: string | {
|
|
4
|
+
id: string;
|
|
5
|
+
clientOnly?: boolean;
|
|
6
|
+
}) => string | undefined;
|
|
7
|
+
/** Node 入口按 basename 托管前端,构建与开发必须生成相同前缀的资源 URL。 */
|
|
8
|
+
declare const _default: vite.UserConfigFnObject;
|
|
9
|
+
|
|
10
|
+
export { adaptPageRoute, _default as default };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as vite from 'vite';
|
|
2
|
+
|
|
3
|
+
declare const adaptPageRoute: (code: string, options: string | {
|
|
4
|
+
id: string;
|
|
5
|
+
clientOnly?: boolean;
|
|
6
|
+
}) => string | undefined;
|
|
7
|
+
/** Node 入口按 basename 托管前端,构建与开发必须生成相同前缀的资源 URL。 */
|
|
8
|
+
declare const _default: vite.UserConfigFnObject;
|
|
9
|
+
|
|
10
|
+
export { adaptPageRoute, _default as default };
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/vite.ts
|
|
31
|
+
var vite_exports = {};
|
|
32
|
+
__export(vite_exports, {
|
|
33
|
+
adaptPageRoute: () => adaptPageRoute,
|
|
34
|
+
default: () => vite_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(vite_exports);
|
|
37
|
+
var import_node_path2 = __toESM(require("path"));
|
|
38
|
+
var import_node_fs2 = require("fs");
|
|
39
|
+
var import_vite = require("@react-router/dev/vite");
|
|
40
|
+
var import_vite2 = require("vite");
|
|
41
|
+
|
|
42
|
+
// src/config.ts
|
|
43
|
+
var import_node_fs = __toESM(require("fs"));
|
|
44
|
+
var import_node_path = __toESM(require("path"));
|
|
45
|
+
var import_node_url = require("url");
|
|
46
|
+
var import_yaml = __toESM(require("yaml"));
|
|
47
|
+
var import_meta = {};
|
|
48
|
+
var DEFAULT_BUILD_DIRECTORY = "dist";
|
|
49
|
+
var protectedDirectories = /* @__PURE__ */ new Set(["src", "types", "public", "node_modules", ".git"]);
|
|
50
|
+
var configDirectory = typeof __dirname === "string" ? __dirname : import_node_path.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
51
|
+
var loadXfeConfig = (root = process.cwd()) => {
|
|
52
|
+
const xfeConfigPath = import_node_path.default.join(root, "xfe.json");
|
|
53
|
+
if (!import_node_fs.default.existsSync(xfeConfigPath)) {
|
|
54
|
+
throw new Error("xfe.json \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA\u8BE5\u6587\u4EF6\u3002");
|
|
55
|
+
}
|
|
56
|
+
const xfeConfigContent = import_node_fs.default.readFileSync(xfeConfigPath, "utf8");
|
|
57
|
+
const config = JSON.parse(xfeConfigContent);
|
|
58
|
+
const renderMode = config.webapp?.renderMode;
|
|
59
|
+
if (renderMode !== void 0 && renderMode !== "client" && renderMode !== "server") {
|
|
60
|
+
throw new Error("xfe.json.webapp.renderMode \u53EA\u80FD\u4E3A client \u6216 server");
|
|
61
|
+
}
|
|
62
|
+
getBuildDirectory(root, config.webapp);
|
|
63
|
+
getServerEntry(root, config.webapp);
|
|
64
|
+
return config;
|
|
65
|
+
};
|
|
66
|
+
var getBuildDirectory = (projectRoot, webapp = {}) => {
|
|
67
|
+
const configured = webapp?.buildDirectory === void 0 ? DEFAULT_BUILD_DIRECTORY : webapp.buildDirectory;
|
|
68
|
+
if (typeof configured !== "string" || !configured.trim() || /[\0\r\n]/.test(configured)) {
|
|
69
|
+
throw new Error("xfe.json.webapp.buildDirectory \u5FC5\u987B\u662F\u975E\u7A7A\u7684\u5355\u884C\u5B57\u7B26\u4E32");
|
|
70
|
+
}
|
|
71
|
+
const directory = configured.trim().replaceAll("\\", "/");
|
|
72
|
+
const root = import_node_path.default.resolve(projectRoot);
|
|
73
|
+
const output = import_node_path.default.resolve(root, directory);
|
|
74
|
+
const relative = import_node_path.default.relative(root, output);
|
|
75
|
+
const [firstDirectory = ""] = relative.split(import_node_path.default.sep);
|
|
76
|
+
const escapesProject = import_node_path.default.isAbsolute(directory) || Boolean(import_node_path.default.win32.parse(directory).root) || firstDirectory === "..";
|
|
77
|
+
const overwritesInput = !relative || protectedDirectories.has(firstDirectory.toLowerCase());
|
|
78
|
+
if (escapesProject || overwritesInput) {
|
|
79
|
+
throw new Error("xfe.json.webapp.buildDirectory \u5FC5\u987B\u662F\u9879\u76EE\u5185\u72EC\u7ACB\u7684\u8F93\u51FA\u76EE\u5F55\uFF0C\u4E0D\u80FD\u8986\u76D6\u9879\u76EE\u3001\u6E90\u7801\u6216\u4F9D\u8D56");
|
|
80
|
+
}
|
|
81
|
+
let currentDirectory = root;
|
|
82
|
+
for (const segment of relative.split(import_node_path.default.sep)) {
|
|
83
|
+
currentDirectory = import_node_path.default.join(currentDirectory, segment);
|
|
84
|
+
if (import_node_fs.default.lstatSync(currentDirectory, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
85
|
+
throw new Error("xfe.json.webapp.buildDirectory \u4E0D\u80FD\u7ECF\u8FC7\u7B26\u53F7\u94FE\u63A5\uFF0C\u4EE5\u514D\u6E05\u7406\u5176\u4ED6\u76EE\u5F55");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return output;
|
|
89
|
+
};
|
|
90
|
+
var getServerEntry = (projectRoot, webapp = {}) => {
|
|
91
|
+
const entry = webapp?.serverEntry;
|
|
92
|
+
if (entry === void 0) return;
|
|
93
|
+
if (typeof entry !== "string" || !entry.trim() || /[\0\r\n]/.test(entry)) {
|
|
94
|
+
throw new Error("xfe.json.webapp.serverEntry \u5FC5\u987B\u662F\u9879\u76EE\u5185\u7684 TypeScript / JavaScript \u76F8\u5BF9\u8DEF\u5F84");
|
|
95
|
+
}
|
|
96
|
+
const normalized = entry.trim().replaceAll("\\", "/");
|
|
97
|
+
const absolute = import_node_path.default.resolve(projectRoot, normalized);
|
|
98
|
+
const relative = import_node_path.default.relative(import_node_path.default.resolve(projectRoot), absolute);
|
|
99
|
+
const outside = Boolean(import_node_path.default.win32.parse(normalized).root) || relative.split(import_node_path.default.sep)[0] === "..";
|
|
100
|
+
if (outside || !/\.(?:[jt]sx?|m[jt]s)$/.test(relative)) {
|
|
101
|
+
throw new Error("xfe.json.webapp.serverEntry \u5FC5\u987B\u662F\u9879\u76EE\u5185\u7684 TypeScript / JavaScript \u76F8\u5BF9\u8DEF\u5F84");
|
|
102
|
+
}
|
|
103
|
+
return absolute;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// src/vite.ts
|
|
107
|
+
var chromeDevToolsConfigPath = "/.well-known/appspecific/com.chrome.devtools.json";
|
|
108
|
+
var adaptPageRoute = (code, options) => {
|
|
109
|
+
const { id, clientOnly = false } = typeof options === "string" ? { id: options } : options;
|
|
110
|
+
if (!/[\\/]pages[\\/].+\.(?:jsx?|tsx?)$/.test(id) || !/^\s*export\s+const\s+page\s*=/m.test(code)) return;
|
|
111
|
+
const fallback = clientOnly ? "" : "export const HydrateFallback = page.HydrateFallback\n";
|
|
112
|
+
return `${code}
|
|
113
|
+
export default page.Component
|
|
114
|
+
export const clientLoader = page.clientLoader
|
|
115
|
+
${fallback}export const ErrorBoundary = page.ErrorBoundary
|
|
116
|
+
export const meta = page.meta
|
|
117
|
+
`;
|
|
118
|
+
};
|
|
119
|
+
var frameworkPlugin = (clientOnly) => ({
|
|
120
|
+
name: "xfe:framework",
|
|
121
|
+
enforce: "pre",
|
|
122
|
+
configureServer(server) {
|
|
123
|
+
server.middlewares.use(chromeDevToolsConfigPath, (_request, response) => response.writeHead(404).end());
|
|
124
|
+
},
|
|
125
|
+
transform(code, id) {
|
|
126
|
+
return adaptPageRoute(code, { id, clientOnly });
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
var vite_default = (0, import_vite2.defineConfig)(({ mode }) => {
|
|
130
|
+
const projectRoot = process.env.XFE_WEB_ROOT;
|
|
131
|
+
if (!projectRoot) throw new Error("\u7F3A\u5C11 XFE_WEB_ROOT\uFF0CVite \u5FC5\u987B\u901A\u8FC7 xfe-web \u542F\u52A8");
|
|
132
|
+
const env = (0, import_vite2.loadEnv)(mode, projectRoot, "");
|
|
133
|
+
const { webapp = {} } = loadXfeConfig(projectRoot);
|
|
134
|
+
const publicEnv = (key) => process.env[key] || env[key] || "";
|
|
135
|
+
return {
|
|
136
|
+
...webapp.serverEntry ? { base: import_node_path2.default.posix.join(webapp.basename || "/", "/") } : {},
|
|
137
|
+
plugins: [frameworkPlugin(webapp.renderMode === "client"), (0, import_vite.reactRouter)()],
|
|
138
|
+
build: { emptyOutDir: true },
|
|
139
|
+
envDir: projectRoot,
|
|
140
|
+
envPrefix: ["VITE_", "REACT_APP_"],
|
|
141
|
+
publicDir: import_node_path2.default.join(projectRoot, "public"),
|
|
142
|
+
define: {
|
|
143
|
+
"import.meta.env.XFE_JWT_AUD": JSON.stringify(publicEnv("XFE_JWT_AUD")),
|
|
144
|
+
"import.meta.env.XFE_JWT_KEY_ID": JSON.stringify(publicEnv("XFE_JWT_KEY_ID")),
|
|
145
|
+
"process.env.REACT_APP_RELEASE": JSON.stringify(publicEnv("REACT_APP_RELEASE")),
|
|
146
|
+
"process.env.REACT_APP_API_ENV": JSON.stringify(publicEnv("REACT_APP_API_ENV")),
|
|
147
|
+
"process.env.REACT_APP_BUSINESS": JSON.stringify(publicEnv("REACT_APP_BUSINESS")),
|
|
148
|
+
"process.env.XFE_JWT_AUD": JSON.stringify(publicEnv("XFE_JWT_AUD")),
|
|
149
|
+
"process.env.XFE_JWT_KEY_ID": JSON.stringify(publicEnv("XFE_JWT_KEY_ID")),
|
|
150
|
+
"process.env.XFE_JWT_PRIVATE_KEY": "undefined"
|
|
151
|
+
},
|
|
152
|
+
css: {
|
|
153
|
+
preprocessorOptions: {
|
|
154
|
+
less: {
|
|
155
|
+
javascriptEnabled: true,
|
|
156
|
+
paths: [import_node_path2.default.join(projectRoot, "src")]
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
resolve: {
|
|
161
|
+
tsconfigPaths: true,
|
|
162
|
+
// workspace 和本地框架链接均使用消费应用的 React 与状态管理实例。
|
|
163
|
+
dedupe: ["react", "react-dom", "react-redux", "@reduxjs/toolkit"].filter(
|
|
164
|
+
(name) => (0, import_node_fs2.existsSync)(import_node_path2.default.join(projectRoot, "node_modules", name))
|
|
165
|
+
)
|
|
166
|
+
},
|
|
167
|
+
ssr: {
|
|
168
|
+
// 路由属于框架内部依赖,SSR/SPA 预渲染产物也不能要求业务项目直接安装它。
|
|
169
|
+
noExternal: ["react-router", "isbot", /^@xfe-repo\/web-/, /^@ant-design\//, /^@emotion\//, /^@rc-component\//, /^rc-/, "antd"]
|
|
170
|
+
},
|
|
171
|
+
server: {
|
|
172
|
+
cors: true,
|
|
173
|
+
fs: { allow: [projectRoot] },
|
|
174
|
+
host: env.HOST || webapp.host || "0.0.0.0",
|
|
175
|
+
port: Number(env.PORT || webapp.port) || 3e3
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
180
|
+
0 && (module.exports = {
|
|
181
|
+
adaptPageRoute
|
|
182
|
+
});
|
package/dist/vite.mjs
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// src/vite.ts
|
|
2
|
+
import path2 from "path";
|
|
3
|
+
import { existsSync } from "fs";
|
|
4
|
+
import { reactRouter } from "@react-router/dev/vite";
|
|
5
|
+
import { defineConfig, loadEnv } from "vite";
|
|
6
|
+
|
|
7
|
+
// src/config.ts
|
|
8
|
+
import fs from "fs";
|
|
9
|
+
import path from "path";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
11
|
+
import yaml from "yaml";
|
|
12
|
+
var DEFAULT_BUILD_DIRECTORY = "dist";
|
|
13
|
+
var protectedDirectories = /* @__PURE__ */ new Set(["src", "types", "public", "node_modules", ".git"]);
|
|
14
|
+
var configDirectory = typeof __dirname === "string" ? __dirname : path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
var loadXfeConfig = (root = process.cwd()) => {
|
|
16
|
+
const xfeConfigPath = path.join(root, "xfe.json");
|
|
17
|
+
if (!fs.existsSync(xfeConfigPath)) {
|
|
18
|
+
throw new Error("xfe.json \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA\u8BE5\u6587\u4EF6\u3002");
|
|
19
|
+
}
|
|
20
|
+
const xfeConfigContent = fs.readFileSync(xfeConfigPath, "utf8");
|
|
21
|
+
const config = JSON.parse(xfeConfigContent);
|
|
22
|
+
const renderMode = config.webapp?.renderMode;
|
|
23
|
+
if (renderMode !== void 0 && renderMode !== "client" && renderMode !== "server") {
|
|
24
|
+
throw new Error("xfe.json.webapp.renderMode \u53EA\u80FD\u4E3A client \u6216 server");
|
|
25
|
+
}
|
|
26
|
+
getBuildDirectory(root, config.webapp);
|
|
27
|
+
getServerEntry(root, config.webapp);
|
|
28
|
+
return config;
|
|
29
|
+
};
|
|
30
|
+
var getBuildDirectory = (projectRoot, webapp = {}) => {
|
|
31
|
+
const configured = webapp?.buildDirectory === void 0 ? DEFAULT_BUILD_DIRECTORY : webapp.buildDirectory;
|
|
32
|
+
if (typeof configured !== "string" || !configured.trim() || /[\0\r\n]/.test(configured)) {
|
|
33
|
+
throw new Error("xfe.json.webapp.buildDirectory \u5FC5\u987B\u662F\u975E\u7A7A\u7684\u5355\u884C\u5B57\u7B26\u4E32");
|
|
34
|
+
}
|
|
35
|
+
const directory = configured.trim().replaceAll("\\", "/");
|
|
36
|
+
const root = path.resolve(projectRoot);
|
|
37
|
+
const output = path.resolve(root, directory);
|
|
38
|
+
const relative = path.relative(root, output);
|
|
39
|
+
const [firstDirectory = ""] = relative.split(path.sep);
|
|
40
|
+
const escapesProject = path.isAbsolute(directory) || Boolean(path.win32.parse(directory).root) || firstDirectory === "..";
|
|
41
|
+
const overwritesInput = !relative || protectedDirectories.has(firstDirectory.toLowerCase());
|
|
42
|
+
if (escapesProject || overwritesInput) {
|
|
43
|
+
throw new Error("xfe.json.webapp.buildDirectory \u5FC5\u987B\u662F\u9879\u76EE\u5185\u72EC\u7ACB\u7684\u8F93\u51FA\u76EE\u5F55\uFF0C\u4E0D\u80FD\u8986\u76D6\u9879\u76EE\u3001\u6E90\u7801\u6216\u4F9D\u8D56");
|
|
44
|
+
}
|
|
45
|
+
let currentDirectory = root;
|
|
46
|
+
for (const segment of relative.split(path.sep)) {
|
|
47
|
+
currentDirectory = path.join(currentDirectory, segment);
|
|
48
|
+
if (fs.lstatSync(currentDirectory, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
49
|
+
throw new Error("xfe.json.webapp.buildDirectory \u4E0D\u80FD\u7ECF\u8FC7\u7B26\u53F7\u94FE\u63A5\uFF0C\u4EE5\u514D\u6E05\u7406\u5176\u4ED6\u76EE\u5F55");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return output;
|
|
53
|
+
};
|
|
54
|
+
var getServerEntry = (projectRoot, webapp = {}) => {
|
|
55
|
+
const entry = webapp?.serverEntry;
|
|
56
|
+
if (entry === void 0) return;
|
|
57
|
+
if (typeof entry !== "string" || !entry.trim() || /[\0\r\n]/.test(entry)) {
|
|
58
|
+
throw new Error("xfe.json.webapp.serverEntry \u5FC5\u987B\u662F\u9879\u76EE\u5185\u7684 TypeScript / JavaScript \u76F8\u5BF9\u8DEF\u5F84");
|
|
59
|
+
}
|
|
60
|
+
const normalized = entry.trim().replaceAll("\\", "/");
|
|
61
|
+
const absolute = path.resolve(projectRoot, normalized);
|
|
62
|
+
const relative = path.relative(path.resolve(projectRoot), absolute);
|
|
63
|
+
const outside = Boolean(path.win32.parse(normalized).root) || relative.split(path.sep)[0] === "..";
|
|
64
|
+
if (outside || !/\.(?:[jt]sx?|m[jt]s)$/.test(relative)) {
|
|
65
|
+
throw new Error("xfe.json.webapp.serverEntry \u5FC5\u987B\u662F\u9879\u76EE\u5185\u7684 TypeScript / JavaScript \u76F8\u5BF9\u8DEF\u5F84");
|
|
66
|
+
}
|
|
67
|
+
return absolute;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/vite.ts
|
|
71
|
+
var chromeDevToolsConfigPath = "/.well-known/appspecific/com.chrome.devtools.json";
|
|
72
|
+
var adaptPageRoute = (code, options) => {
|
|
73
|
+
const { id, clientOnly = false } = typeof options === "string" ? { id: options } : options;
|
|
74
|
+
if (!/[\\/]pages[\\/].+\.(?:jsx?|tsx?)$/.test(id) || !/^\s*export\s+const\s+page\s*=/m.test(code)) return;
|
|
75
|
+
const fallback = clientOnly ? "" : "export const HydrateFallback = page.HydrateFallback\n";
|
|
76
|
+
return `${code}
|
|
77
|
+
export default page.Component
|
|
78
|
+
export const clientLoader = page.clientLoader
|
|
79
|
+
${fallback}export const ErrorBoundary = page.ErrorBoundary
|
|
80
|
+
export const meta = page.meta
|
|
81
|
+
`;
|
|
82
|
+
};
|
|
83
|
+
var frameworkPlugin = (clientOnly) => ({
|
|
84
|
+
name: "xfe:framework",
|
|
85
|
+
enforce: "pre",
|
|
86
|
+
configureServer(server) {
|
|
87
|
+
server.middlewares.use(chromeDevToolsConfigPath, (_request, response) => response.writeHead(404).end());
|
|
88
|
+
},
|
|
89
|
+
transform(code, id) {
|
|
90
|
+
return adaptPageRoute(code, { id, clientOnly });
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
var vite_default = defineConfig(({ mode }) => {
|
|
94
|
+
const projectRoot = process.env.XFE_WEB_ROOT;
|
|
95
|
+
if (!projectRoot) throw new Error("\u7F3A\u5C11 XFE_WEB_ROOT\uFF0CVite \u5FC5\u987B\u901A\u8FC7 xfe-web \u542F\u52A8");
|
|
96
|
+
const env = loadEnv(mode, projectRoot, "");
|
|
97
|
+
const { webapp = {} } = loadXfeConfig(projectRoot);
|
|
98
|
+
const publicEnv = (key) => process.env[key] || env[key] || "";
|
|
99
|
+
return {
|
|
100
|
+
...webapp.serverEntry ? { base: path2.posix.join(webapp.basename || "/", "/") } : {},
|
|
101
|
+
plugins: [frameworkPlugin(webapp.renderMode === "client"), reactRouter()],
|
|
102
|
+
build: { emptyOutDir: true },
|
|
103
|
+
envDir: projectRoot,
|
|
104
|
+
envPrefix: ["VITE_", "REACT_APP_"],
|
|
105
|
+
publicDir: path2.join(projectRoot, "public"),
|
|
106
|
+
define: {
|
|
107
|
+
"import.meta.env.XFE_JWT_AUD": JSON.stringify(publicEnv("XFE_JWT_AUD")),
|
|
108
|
+
"import.meta.env.XFE_JWT_KEY_ID": JSON.stringify(publicEnv("XFE_JWT_KEY_ID")),
|
|
109
|
+
"process.env.REACT_APP_RELEASE": JSON.stringify(publicEnv("REACT_APP_RELEASE")),
|
|
110
|
+
"process.env.REACT_APP_API_ENV": JSON.stringify(publicEnv("REACT_APP_API_ENV")),
|
|
111
|
+
"process.env.REACT_APP_BUSINESS": JSON.stringify(publicEnv("REACT_APP_BUSINESS")),
|
|
112
|
+
"process.env.XFE_JWT_AUD": JSON.stringify(publicEnv("XFE_JWT_AUD")),
|
|
113
|
+
"process.env.XFE_JWT_KEY_ID": JSON.stringify(publicEnv("XFE_JWT_KEY_ID")),
|
|
114
|
+
"process.env.XFE_JWT_PRIVATE_KEY": "undefined"
|
|
115
|
+
},
|
|
116
|
+
css: {
|
|
117
|
+
preprocessorOptions: {
|
|
118
|
+
less: {
|
|
119
|
+
javascriptEnabled: true,
|
|
120
|
+
paths: [path2.join(projectRoot, "src")]
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
resolve: {
|
|
125
|
+
tsconfigPaths: true,
|
|
126
|
+
// workspace 和本地框架链接均使用消费应用的 React 与状态管理实例。
|
|
127
|
+
dedupe: ["react", "react-dom", "react-redux", "@reduxjs/toolkit"].filter(
|
|
128
|
+
(name) => existsSync(path2.join(projectRoot, "node_modules", name))
|
|
129
|
+
)
|
|
130
|
+
},
|
|
131
|
+
ssr: {
|
|
132
|
+
// 路由属于框架内部依赖,SSR/SPA 预渲染产物也不能要求业务项目直接安装它。
|
|
133
|
+
noExternal: ["react-router", "isbot", /^@xfe-repo\/web-/, /^@ant-design\//, /^@emotion\//, /^@rc-component\//, /^rc-/, "antd"]
|
|
134
|
+
},
|
|
135
|
+
server: {
|
|
136
|
+
cors: true,
|
|
137
|
+
fs: { allow: [projectRoot] },
|
|
138
|
+
host: env.HOST || webapp.host || "0.0.0.0",
|
|
139
|
+
port: Number(env.PORT || webapp.port) || 3e3
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
export {
|
|
144
|
+
adaptPageRoute,
|
|
145
|
+
vite_default as default
|
|
146
|
+
};
|
package/package.json
CHANGED
|
@@ -1,90 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xfe-repo/web-app",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"bin": {
|
|
5
5
|
"xfe-web": "./bin/index.js"
|
|
6
6
|
},
|
|
7
7
|
"files": [
|
|
8
8
|
"dist",
|
|
9
9
|
"bin",
|
|
10
|
-
"config",
|
|
11
10
|
"deploy",
|
|
12
|
-
"scripts",
|
|
13
11
|
"tsconfig.json",
|
|
12
|
+
"client.d.ts",
|
|
14
13
|
".eslintrc.js"
|
|
15
14
|
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=22.22.0"
|
|
17
|
+
},
|
|
16
18
|
"dependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"@
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"@testing-library/react": "^16.3.2",
|
|
25
|
-
"@testing-library/user-event": "^14.6.1",
|
|
26
|
-
"@types/minimist": "^1.2.5",
|
|
27
|
-
"@types/node": "^20.17.0",
|
|
28
|
-
"@types/react": "^18.0.0",
|
|
29
|
-
"babel-jest": "^30.2.0",
|
|
30
|
-
"babel-loader": "^8.2.3",
|
|
31
|
-
"babel-plugin-named-asset-import": "^0.3.8",
|
|
32
|
-
"babel-preset-react-app": "^10.0.1",
|
|
33
|
-
"bfj": "^7.0.2",
|
|
34
|
-
"browserslist": "^4.18.1",
|
|
35
|
-
"camelcase": "^6.2.1",
|
|
36
|
-
"case-sensitive-paths-webpack-plugin": "^2.4.0",
|
|
37
|
-
"css-loader": "^6.5.1",
|
|
38
|
-
"css-minimizer-webpack-plugin": "^3.2.0",
|
|
39
|
-
"dotenv": "^10.0.0",
|
|
40
|
-
"dotenv-expand": "^5.1.0",
|
|
41
|
-
"eslint": "8.57.1",
|
|
42
|
-
"eslint-config-react-app": "^7.0.1",
|
|
43
|
-
"eslint-webpack-plugin": "^3.1.1",
|
|
44
|
-
"file-loader": "^6.2.0",
|
|
45
|
-
"fs-extra": "^10.0.0",
|
|
46
|
-
"html-webpack-plugin": "^5.5.0",
|
|
47
|
-
"husky": "^9.1.6",
|
|
48
|
-
"identity-obj-proxy": "^3.0.0",
|
|
49
|
-
"ignore-loader": "^0.1.2",
|
|
50
|
-
"jest": "^30.2.0",
|
|
51
|
-
"jest-resolve": "^30.2.0",
|
|
52
|
-
"jest-watch-typeahead": "^3.0.1",
|
|
19
|
+
"@react-router/dev": "8.3.0",
|
|
20
|
+
"@react-router/express": "8.3.0",
|
|
21
|
+
"@react-router/serve": "8.3.0",
|
|
22
|
+
"@types/node": "^22.0.0",
|
|
23
|
+
"esbuild": "^0.27.7",
|
|
24
|
+
"express": "5.2.1",
|
|
25
|
+
"isbot": "^5.1.36",
|
|
53
26
|
"less": "^4.1.3",
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
"react-dev-utils": "^12.0.1",
|
|
66
|
-
"react-refresh": "^0.11.0",
|
|
67
|
-
"resolve": "^1.20.0",
|
|
68
|
-
"resolve-url-loader": "^4.0.0",
|
|
69
|
-
"sass-loader": "^12.3.0",
|
|
70
|
-
"semver": "^7.3.5",
|
|
71
|
-
"source-map-loader": "^3.0.0",
|
|
72
|
-
"style-loader": "^3.3.1",
|
|
73
|
-
"tailwindcss": "^3.0.2",
|
|
74
|
-
"terser-webpack-plugin": "^5.2.5",
|
|
75
|
-
"web-vitals": "^2.1.4",
|
|
76
|
-
"webpack": "~5.64.4",
|
|
77
|
-
"webpack-bundle-analyzer": "^4.8.0",
|
|
78
|
-
"webpack-dev-server": "^4.6.0",
|
|
79
|
-
"webpack-manifest-plugin": "^4.0.2",
|
|
80
|
-
"workbox-webpack-plugin": "^7.0.0",
|
|
81
|
-
"yaml": "^2.3.4",
|
|
82
|
-
"@xfe-repo/typescript-config": "1.6.2",
|
|
83
|
-
"@xfe-repo/eslint-config": "1.6.0"
|
|
27
|
+
"react-router": "8.3.0",
|
|
28
|
+
"typescript": "~5.9.3",
|
|
29
|
+
"vite": "^8.2.1",
|
|
30
|
+
"yaml": "^2.4.2",
|
|
31
|
+
"tsx": "4.23.15",
|
|
32
|
+
"@xfe-repo/eslint-config": "2.0.0-beta.1",
|
|
33
|
+
"@xfe-repo/web-router": "2.0.0-beta.1",
|
|
34
|
+
"@xfe-repo/typescript-config": "2.0.0-beta.1"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/express": "5.0.6"
|
|
84
38
|
},
|
|
85
39
|
"peerDependencies": {
|
|
86
|
-
"react": "
|
|
87
|
-
"react-dom": "
|
|
40
|
+
"react": ">=19.2.7",
|
|
41
|
+
"react-dom": ">=19.2.7"
|
|
88
42
|
},
|
|
89
43
|
"publishConfig": {
|
|
90
44
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -93,6 +47,7 @@
|
|
|
93
47
|
"build": "tsup",
|
|
94
48
|
"dev": "tsup --watch",
|
|
95
49
|
"lint": "eslint \"src/**/*.ts*\" --fix",
|
|
96
|
-
"clean": "rm -rf .turbo coverage dist node_modules"
|
|
50
|
+
"clean": "rm -rf .turbo coverage dist node_modules",
|
|
51
|
+
"test": "pnpm build && node --test test/*.test.cjs"
|
|
97
52
|
}
|
|
98
53
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "@xfe-repo/typescript-config/react.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
+
"target": "ES2022",
|
|
5
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
6
|
+
"types": ["node"],
|
|
4
7
|
"paths": {
|
|
5
8
|
"@/*": ["./*"],
|
|
6
9
|
"@/types/*": ["../types/*"],
|
|
7
10
|
"@common/services": ["../node_modules/@xfe-repo/web-service/dist/index"]
|
|
8
11
|
}
|
|
9
12
|
},
|
|
10
|
-
"exclude": ["node_modules", "build", "dist"]
|
|
13
|
+
"exclude": ["node_modules", "build", "dist", ".react-router"]
|
|
11
14
|
}
|