@lark-apaas/coding-html-devserver 0.1.1 → 0.1.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/lib/build.d.ts +6 -0
- package/lib/build.js +14 -1
- package/lib/index.d.ts +5 -0
- package/lib/index.js +10 -1
- package/lib/normalize-base-path.d.ts +6 -0
- package/lib/normalize-base-path.js +16 -0
- package/lib/plugins/routes-json.d.ts +16 -0
- package/lib/plugins/routes-json.js +23 -0
- package/lib/routes.d.ts +31 -0
- package/lib/routes.js +115 -0
- package/lib/vite-config.js +5 -14
- package/package.json +1 -1
package/lib/build.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export interface BuildResult {
|
|
|
11
11
|
readonly outDir: string;
|
|
12
12
|
/** 注入(并按需压缩)过的 html 产物绝对路径列表。 */
|
|
13
13
|
readonly htmlFiles: string[];
|
|
14
|
+
/** routes.json 产物绝对路径(源里有则透传、没有则补默认)。 */
|
|
15
|
+
readonly routesJson: string;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* build:把 `root` 全量**纯拷贝**到 `outDir`(文件名/路径/结构逐字保留),
|
|
@@ -18,5 +20,9 @@ export interface BuildResult {
|
|
|
18
20
|
*
|
|
19
21
|
* 不走 vite build —— 不打包、不加 hash、不改写路径,保证「产物 = 源码」。
|
|
20
22
|
* 注入与 dev 共用 `injectPlatformTags`,两条路一致。
|
|
23
|
+
*
|
|
24
|
+
* routes.json(平台路由清单):纯拷贝已把源里手维护的带出来(透传);若源没有,则扫描
|
|
25
|
+
* `root` 下的 `*.html` 生成 `[{path}]`,**带上 `CLIENT_BASE_PATH` 前缀**(build 场景)。
|
|
26
|
+
* MPA 由物理 .html 直出,routes.json 列出页面路由。
|
|
21
27
|
*/
|
|
22
28
|
export declare function buildStatic(opts?: BuildOptions): Promise<BuildResult>;
|
package/lib/build.js
CHANGED
|
@@ -8,6 +8,8 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const transform_1 = require("./transform");
|
|
10
10
|
const minify_1 = require("./minify");
|
|
11
|
+
const routes_1 = require("./routes");
|
|
12
|
+
const normalize_base_path_1 = require("./normalize-base-path");
|
|
11
13
|
const HTML_EXT = new Set(['.html', '.htm']);
|
|
12
14
|
/**
|
|
13
15
|
* build:把 `root` 全量**纯拷贝**到 `outDir`(文件名/路径/结构逐字保留),
|
|
@@ -15,6 +17,10 @@ const HTML_EXT = new Set(['.html', '.htm']);
|
|
|
15
17
|
*
|
|
16
18
|
* 不走 vite build —— 不打包、不加 hash、不改写路径,保证「产物 = 源码」。
|
|
17
19
|
* 注入与 dev 共用 `injectPlatformTags`,两条路一致。
|
|
20
|
+
*
|
|
21
|
+
* routes.json(平台路由清单):纯拷贝已把源里手维护的带出来(透传);若源没有,则扫描
|
|
22
|
+
* `root` 下的 `*.html` 生成 `[{path}]`,**带上 `CLIENT_BASE_PATH` 前缀**(build 场景)。
|
|
23
|
+
* MPA 由物理 .html 直出,routes.json 列出页面路由。
|
|
18
24
|
*/
|
|
19
25
|
async function buildStatic(opts = {}) {
|
|
20
26
|
const root = node_path_1.default.resolve(opts.root ?? 'src');
|
|
@@ -36,7 +42,14 @@ async function buildStatic(opts = {}) {
|
|
|
36
42
|
await node_fs_1.default.promises.writeFile(file, html, 'utf8');
|
|
37
43
|
htmlFiles.push(file);
|
|
38
44
|
}
|
|
39
|
-
|
|
45
|
+
// 源根有 routes.json → 纯拷贝已带出(透传手维护版);没有 → 扫描生成(带 CLIENT_BASE_PATH 前缀)
|
|
46
|
+
const routesJson = node_path_1.default.join(outDir, routes_1.ROUTES_JSON_FILENAME);
|
|
47
|
+
if (!node_fs_1.default.existsSync(routesJson)) {
|
|
48
|
+
const basePath = (0, normalize_base_path_1.normalizeBasePath)(process.env.CLIENT_BASE_PATH);
|
|
49
|
+
const routes = (0, routes_1.generateRoutes)(root, basePath);
|
|
50
|
+
await node_fs_1.default.promises.writeFile(routesJson, JSON.stringify(routes, null, 2) + '\n', 'utf8');
|
|
51
|
+
}
|
|
52
|
+
return { root, outDir, htmlFiles, routesJson };
|
|
40
53
|
}
|
|
41
54
|
function* walk(dir) {
|
|
42
55
|
for (const entry of node_fs_1.default.readdirSync(dir, { withFileTypes: true })) {
|
package/lib/index.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ export type { HtmlViteOptions } from './vite-config';
|
|
|
4
4
|
export { buildStatic } from './build';
|
|
5
5
|
export type { BuildOptions, BuildResult } from './build';
|
|
6
6
|
export { minifyHtmlWithHbsProtection } from './minify';
|
|
7
|
+
export { generateRoutes, resolveRoutesJson, routePathFromFile, ROUTES_JSON_FILENAME, } from './routes';
|
|
8
|
+
export type { RouteEntry } from './routes';
|
|
9
|
+
export { normalizeBasePath } from './normalize-base-path';
|
|
7
10
|
export { injectPlatformTags, PLATFORM_TAGS } from './transform';
|
|
8
11
|
export type { InjectPlatformOptions } from './transform';
|
|
9
12
|
export { viewContextTag, buildRenderContext } from './transform/view-context';
|
|
@@ -22,3 +25,5 @@ export { viteClientPatchPlugin } from './plugins/vite-client-patch';
|
|
|
22
25
|
export { wsWatchdogPlugin } from './plugins/ws-watchdog';
|
|
23
26
|
export type { WsWatchdogPluginOptions } from './plugins/ws-watchdog';
|
|
24
27
|
export { basePathRewritePlugin } from './plugins/base-path';
|
|
28
|
+
export { routesJsonPlugin } from './plugins/routes-json';
|
|
29
|
+
export type { RoutesJsonPluginOptions } from './plugins/routes-json';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.basePathRewritePlugin = exports.wsWatchdogPlugin = exports.viteClientPatchPlugin = exports.platformInjectPlugin = exports.HEALTH_ENDPOINT = exports.healthPlugin = exports.serializeTag = exports.injectTags = exports.injectOgMeta = exports.MIAODA_PREVIEW_BRIDGE_URL = exports.previewBridgeTags = exports.slardarTags = exports.buildRenderContext = exports.viewContextTag = exports.PLATFORM_TAGS = exports.injectPlatformTags = exports.minifyHtmlWithHbsProtection = exports.buildStatic = exports.createHtmlViteConfig = exports.startDevServer = void 0;
|
|
3
|
+
exports.routesJsonPlugin = exports.basePathRewritePlugin = exports.wsWatchdogPlugin = exports.viteClientPatchPlugin = exports.platformInjectPlugin = exports.HEALTH_ENDPOINT = exports.healthPlugin = exports.serializeTag = exports.injectTags = exports.injectOgMeta = exports.MIAODA_PREVIEW_BRIDGE_URL = exports.previewBridgeTags = exports.slardarTags = exports.buildRenderContext = exports.viewContextTag = exports.PLATFORM_TAGS = exports.injectPlatformTags = exports.normalizeBasePath = exports.ROUTES_JSON_FILENAME = exports.routePathFromFile = exports.resolveRoutesJson = exports.generateRoutes = exports.minifyHtmlWithHbsProtection = exports.buildStatic = exports.createHtmlViteConfig = exports.startDevServer = void 0;
|
|
4
4
|
var dev_1 = require("./dev");
|
|
5
5
|
Object.defineProperty(exports, "startDevServer", { enumerable: true, get: function () { return dev_1.startDevServer; } });
|
|
6
6
|
var vite_config_1 = require("./vite-config");
|
|
@@ -9,6 +9,13 @@ var build_1 = require("./build");
|
|
|
9
9
|
Object.defineProperty(exports, "buildStatic", { enumerable: true, get: function () { return build_1.buildStatic; } });
|
|
10
10
|
var minify_1 = require("./minify");
|
|
11
11
|
Object.defineProperty(exports, "minifyHtmlWithHbsProtection", { enumerable: true, get: function () { return minify_1.minifyHtmlWithHbsProtection; } });
|
|
12
|
+
var routes_1 = require("./routes");
|
|
13
|
+
Object.defineProperty(exports, "generateRoutes", { enumerable: true, get: function () { return routes_1.generateRoutes; } });
|
|
14
|
+
Object.defineProperty(exports, "resolveRoutesJson", { enumerable: true, get: function () { return routes_1.resolveRoutesJson; } });
|
|
15
|
+
Object.defineProperty(exports, "routePathFromFile", { enumerable: true, get: function () { return routes_1.routePathFromFile; } });
|
|
16
|
+
Object.defineProperty(exports, "ROUTES_JSON_FILENAME", { enumerable: true, get: function () { return routes_1.ROUTES_JSON_FILENAME; } });
|
|
17
|
+
var normalize_base_path_1 = require("./normalize-base-path");
|
|
18
|
+
Object.defineProperty(exports, "normalizeBasePath", { enumerable: true, get: function () { return normalize_base_path_1.normalizeBasePath; } });
|
|
12
19
|
var transform_1 = require("./transform");
|
|
13
20
|
Object.defineProperty(exports, "injectPlatformTags", { enumerable: true, get: function () { return transform_1.injectPlatformTags; } });
|
|
14
21
|
Object.defineProperty(exports, "PLATFORM_TAGS", { enumerable: true, get: function () { return transform_1.PLATFORM_TAGS; } });
|
|
@@ -36,3 +43,5 @@ var ws_watchdog_1 = require("./plugins/ws-watchdog");
|
|
|
36
43
|
Object.defineProperty(exports, "wsWatchdogPlugin", { enumerable: true, get: function () { return ws_watchdog_1.wsWatchdogPlugin; } });
|
|
37
44
|
var base_path_1 = require("./plugins/base-path");
|
|
38
45
|
Object.defineProperty(exports, "basePathRewritePlugin", { enumerable: true, get: function () { return base_path_1.basePathRewritePlugin; } });
|
|
46
|
+
var routes_json_1 = require("./plugins/routes-json");
|
|
47
|
+
Object.defineProperty(exports, "routesJsonPlugin", { enumerable: true, get: function () { return routes_json_1.routesJsonPlugin; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeBasePath = normalizeBasePath;
|
|
4
|
+
/**
|
|
5
|
+
* 标准化 base path(路径语义,强制 `/` 前缀、去尾斜杠):
|
|
6
|
+
* '' / undefined / '/' → '';'foo' → '/foo';'/app/x/' → '/app/x'。
|
|
7
|
+
* 语义对齐 `@lark-apaas/coding-preset-vite-react` 的 normalizeBasePath。
|
|
8
|
+
*/
|
|
9
|
+
function normalizeBasePath(input) {
|
|
10
|
+
if (!input)
|
|
11
|
+
return '';
|
|
12
|
+
const p = input.trim();
|
|
13
|
+
if (!p || p === '/')
|
|
14
|
+
return '';
|
|
15
|
+
return (p.startsWith('/') ? p : '/' + p).replace(/\/+$/, '');
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* dev 期在 `${clientBasePath}/routes.json` 提供路由清单(与 build 一致):源根有 routes.json
|
|
4
|
+
* 则透传,没有则扫描 `*.html` 生成 `[{path}]`。
|
|
5
|
+
*
|
|
6
|
+
* 路由 path **不带 base 前缀**(对齐 vite-react dev:base 由前缀消费方/网关处理;build 才带
|
|
7
|
+
* `CLIENT_BASE_PATH`)。显式 middleware 而非依赖 vite 静态托管:源无该文件时也能即时生成。
|
|
8
|
+
*/
|
|
9
|
+
export interface RoutesJsonPluginOptions {
|
|
10
|
+
/** dev server root(vite 已 resolve 的绝对路径)。 */
|
|
11
|
+
root: string;
|
|
12
|
+
/** 客户端 base path(如 `/app/app_xxx`);空串退化到裸 `/routes.json`。 */
|
|
13
|
+
clientBasePath?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function routesJsonPlugin(options: RoutesJsonPluginOptions): Plugin;
|
|
16
|
+
export default routesJsonPlugin;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.routesJsonPlugin = routesJsonPlugin;
|
|
4
|
+
const routes_1 = require("../routes");
|
|
5
|
+
function routesJsonPlugin(options) {
|
|
6
|
+
const { root, clientBasePath = '' } = options;
|
|
7
|
+
const urlPath = `${clientBasePath}/${routes_1.ROUTES_JSON_FILENAME}`;
|
|
8
|
+
return {
|
|
9
|
+
name: 'miaoda-html-routes-json',
|
|
10
|
+
apply: 'serve',
|
|
11
|
+
configureServer(server) {
|
|
12
|
+
server.middlewares.use((req, res, next) => {
|
|
13
|
+
const pathname = (req.url || '').split('?')[0];
|
|
14
|
+
if (pathname !== urlPath)
|
|
15
|
+
return next();
|
|
16
|
+
res.setHeader('Content-Type', 'application/json');
|
|
17
|
+
res.setHeader('Cache-Control', 'no-cache');
|
|
18
|
+
res.end((0, routes_1.resolveRoutesJson)(root, ''));
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.default = routesJsonPlugin;
|
package/lib/routes.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML 栈的路由清单 `routes.json`。
|
|
3
|
+
*
|
|
4
|
+
* 平台部署运行时(vefaas/沙箱网关)消费,格式对齐 `@lark-apaas/coding-preset-vite-react`
|
|
5
|
+
* 的 routesPlugin —— `[{ "path": "..." }]` 数组。vite-react 解析 `app.tsx` 的 `<Route>`;
|
|
6
|
+
* HTML 栈没有 Router,**扫描 root 下的 `*.html` 文件**,每个文件即一条路由(MPA)。
|
|
7
|
+
*
|
|
8
|
+
* 路径推导(与确认的规则一致):
|
|
9
|
+
* index.html → /
|
|
10
|
+
* about.html → /about
|
|
11
|
+
* about/index.html → /about
|
|
12
|
+
* foo/bar.html → /foo/bar
|
|
13
|
+
* 再按 basePath 前缀(build 带 `CLIENT_BASE_PATH`,dev 空)。
|
|
14
|
+
*
|
|
15
|
+
* 源根已有手维护的 routes.json → 原样透传,不覆盖。
|
|
16
|
+
*/
|
|
17
|
+
export declare const ROUTES_JSON_FILENAME = "routes.json";
|
|
18
|
+
export interface RouteEntry {
|
|
19
|
+
path: string;
|
|
20
|
+
}
|
|
21
|
+
/** 单个 .html 相对路径 → 路由 path(折叠 index、去扩展名、归一斜杠)。 */
|
|
22
|
+
export declare function routePathFromFile(rel: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* 扫描 root 下的 `*.html` 生成路由列表,按 basePath 前缀。
|
|
25
|
+
* 无任何 html 时回退到单条根路由(对齐 vite-react 的 fallback)。
|
|
26
|
+
*/
|
|
27
|
+
export declare function generateRoutes(root: string, basePath?: string): RouteEntry[];
|
|
28
|
+
/**
|
|
29
|
+
* 源根有 routes.json 则原样返回(手维护优先),否则扫描生成。dev 与 build 共用。
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveRoutesJson(root: string, basePath?: string): string;
|
package/lib/routes.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ROUTES_JSON_FILENAME = void 0;
|
|
37
|
+
exports.routePathFromFile = routePathFromFile;
|
|
38
|
+
exports.generateRoutes = generateRoutes;
|
|
39
|
+
exports.resolveRoutesJson = resolveRoutesJson;
|
|
40
|
+
const fs = __importStar(require("node:fs"));
|
|
41
|
+
const path = __importStar(require("node:path"));
|
|
42
|
+
/**
|
|
43
|
+
* HTML 栈的路由清单 `routes.json`。
|
|
44
|
+
*
|
|
45
|
+
* 平台部署运行时(vefaas/沙箱网关)消费,格式对齐 `@lark-apaas/coding-preset-vite-react`
|
|
46
|
+
* 的 routesPlugin —— `[{ "path": "..." }]` 数组。vite-react 解析 `app.tsx` 的 `<Route>`;
|
|
47
|
+
* HTML 栈没有 Router,**扫描 root 下的 `*.html` 文件**,每个文件即一条路由(MPA)。
|
|
48
|
+
*
|
|
49
|
+
* 路径推导(与确认的规则一致):
|
|
50
|
+
* index.html → /
|
|
51
|
+
* about.html → /about
|
|
52
|
+
* about/index.html → /about
|
|
53
|
+
* foo/bar.html → /foo/bar
|
|
54
|
+
* 再按 basePath 前缀(build 带 `CLIENT_BASE_PATH`,dev 空)。
|
|
55
|
+
*
|
|
56
|
+
* 源根已有手维护的 routes.json → 原样透传,不覆盖。
|
|
57
|
+
*/
|
|
58
|
+
exports.ROUTES_JSON_FILENAME = 'routes.json';
|
|
59
|
+
const HTML_EXT = /\.html?$/i;
|
|
60
|
+
const SKIP_DIRS = new Set(['node_modules', 'dist', '.git']);
|
|
61
|
+
function* walkHtml(dir, base) {
|
|
62
|
+
let entries;
|
|
63
|
+
try {
|
|
64
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
for (const entry of entries) {
|
|
70
|
+
const full = path.join(dir, entry.name);
|
|
71
|
+
if (entry.isDirectory()) {
|
|
72
|
+
if (SKIP_DIRS.has(entry.name) || entry.name.startsWith('.'))
|
|
73
|
+
continue;
|
|
74
|
+
yield* walkHtml(full, base);
|
|
75
|
+
}
|
|
76
|
+
else if (HTML_EXT.test(entry.name)) {
|
|
77
|
+
yield path.relative(base, full);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** 单个 .html 相对路径 → 路由 path(折叠 index、去扩展名、归一斜杠)。 */
|
|
82
|
+
function routePathFromFile(rel) {
|
|
83
|
+
const stripped = rel
|
|
84
|
+
.replace(/\\/g, '/') // win 分隔符归一
|
|
85
|
+
.replace(/\.html?$/i, '') // 去 .html/.htm
|
|
86
|
+
.replace(/(^|\/)index$/i, '$1'); // 折叠尾部 index
|
|
87
|
+
return '/' + stripped.replace(/^\/+/, '').replace(/\/+$/, '');
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 扫描 root 下的 `*.html` 生成路由列表,按 basePath 前缀。
|
|
91
|
+
* 无任何 html 时回退到单条根路由(对齐 vite-react 的 fallback)。
|
|
92
|
+
*/
|
|
93
|
+
function generateRoutes(root, basePath = '') {
|
|
94
|
+
const set = new Set();
|
|
95
|
+
for (const rel of walkHtml(root, root)) {
|
|
96
|
+
set.add(routePathFromFile(rel));
|
|
97
|
+
}
|
|
98
|
+
const paths = Array.from(set).sort();
|
|
99
|
+
const prefixed = paths.length > 0 ? paths.map((p) => (basePath ? basePath + p : p)) : [basePath ? `${basePath}/` : '/'];
|
|
100
|
+
return prefixed.map((p) => ({ path: p }));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 源根有 routes.json 则原样返回(手维护优先),否则扫描生成。dev 与 build 共用。
|
|
104
|
+
*/
|
|
105
|
+
function resolveRoutesJson(root, basePath = '') {
|
|
106
|
+
const p = path.join(root, exports.ROUTES_JSON_FILENAME);
|
|
107
|
+
try {
|
|
108
|
+
if (fs.existsSync(p))
|
|
109
|
+
return fs.readFileSync(p, 'utf8');
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
/* 读失败退化到扫描生成 */
|
|
113
|
+
}
|
|
114
|
+
return JSON.stringify(generateRoutes(root, basePath), null, 2);
|
|
115
|
+
}
|
package/lib/vite-config.js
CHANGED
|
@@ -10,19 +10,8 @@ const inject_1 = require("./plugins/inject");
|
|
|
10
10
|
const vite_client_patch_1 = require("./plugins/vite-client-patch");
|
|
11
11
|
const ws_watchdog_1 = require("./plugins/ws-watchdog");
|
|
12
12
|
const base_path_1 = require("./plugins/base-path");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* '' / undefined / '/' → '';'foo' → '/foo';'/app/x/' → '/app/x'。
|
|
16
|
-
* 语义对齐 `@lark-apaas/coding-preset-vite-react` 的 normalizeBasePath。
|
|
17
|
-
*/
|
|
18
|
-
function normalizeBasePath(input) {
|
|
19
|
-
if (!input)
|
|
20
|
-
return '';
|
|
21
|
-
const p = input.trim();
|
|
22
|
-
if (!p || p === '/')
|
|
23
|
-
return '';
|
|
24
|
-
return (p.startsWith('/') ? p : '/' + p).replace(/\/+$/, '');
|
|
25
|
-
}
|
|
13
|
+
const routes_json_1 = require("./plugins/routes-json");
|
|
14
|
+
const normalize_base_path_1 = require("./normalize-base-path");
|
|
26
15
|
/**
|
|
27
16
|
* html stack 的 vite dev 配置(仅 dev 用,build 不走 vite)。
|
|
28
17
|
*
|
|
@@ -47,7 +36,7 @@ function createHtmlViteConfig(opts = {}) {
|
|
|
47
36
|
const host = opts.host ?? '0.0.0.0';
|
|
48
37
|
// 沙箱网关把 `/app/<id>` 前缀透传给 vite 时,watchdog 的 <script src>、middleware
|
|
49
38
|
// 匹配路径、以及客户端 import 的 `/@vite/client` 都必须带同一前缀;空串退化到裸路径。
|
|
50
|
-
const clientBasePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
|
39
|
+
const clientBasePath = (0, normalize_base_path_1.normalizeBasePath)(process.env.CLIENT_BASE_PATH);
|
|
51
40
|
// 从 `/app/<appId>` 形态的 base path 提取 appId 给 view-context 拼真值;非该形态则
|
|
52
41
|
// 留空,view-context dev 退化为从 URL 解析。
|
|
53
42
|
const appId = /^\/app\/[^/]/.test(clientBasePath)
|
|
@@ -78,6 +67,8 @@ function createHtmlViteConfig(opts = {}) {
|
|
|
78
67
|
(0, ws_watchdog_1.wsWatchdogPlugin)({ clientBasePath }),
|
|
79
68
|
// base 非 `/` 时,把无尾斜杠的 `/app/<id>` 内部 rewrite 成带尾斜杠(自守卫空 base)
|
|
80
69
|
(0, base_path_1.basePathRewritePlugin)(clientBasePath),
|
|
70
|
+
// 在 `${base}routes.json` 提供路由清单(与 build 产物一致)
|
|
71
|
+
(0, routes_json_1.routesJsonPlugin)({ root, clientBasePath }),
|
|
81
72
|
],
|
|
82
73
|
};
|
|
83
74
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/coding-html-devserver",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Dev/build toolchain for the miaoda-coding html (pure HTML) stack. Wraps vite (dev + HMR) behind a bin so the template never sees vite; build is pure-copy + platform-script injection + optional minify.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|