@lark-apaas/coding-html-devserver 0.1.4 → 0.1.5-alpha.1

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.
@@ -0,0 +1,12 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * .jsx 走客户端编译,在 Vite transform 管线前原样返回。
4
+ *
5
+ * 不能用 `esbuild.exclude`:esbuild 跳过后 `vite:import-analysis` 仍会
6
+ * 用 es-module-lexer 解析文件,遇到 JSX 语法直接报错。middleware 在
7
+ * Vite 内置 transform 之前拦截请求,彻底绕过整条管线。
8
+ */
9
+ export declare function rawJsxPlugin(opts: {
10
+ root: string;
11
+ clientBasePath: string;
12
+ }): Plugin;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.rawJsxPlugin = rawJsxPlugin;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ /**
10
+ * .jsx 走客户端编译,在 Vite transform 管线前原样返回。
11
+ *
12
+ * 不能用 `esbuild.exclude`:esbuild 跳过后 `vite:import-analysis` 仍会
13
+ * 用 es-module-lexer 解析文件,遇到 JSX 语法直接报错。middleware 在
14
+ * Vite 内置 transform 之前拦截请求,彻底绕过整条管线。
15
+ */
16
+ function rawJsxPlugin(opts) {
17
+ const { root, clientBasePath } = opts;
18
+ return {
19
+ name: 'miaoda-html-raw-jsx',
20
+ apply: 'serve',
21
+ configureServer(server) {
22
+ server.middlewares.use((req, res, next) => {
23
+ const url = (req.url ?? '').split('?')[0];
24
+ if (!url.endsWith('.jsx'))
25
+ return next();
26
+ const stripped = clientBasePath && url.startsWith(clientBasePath) ? url.slice(clientBasePath.length) : url;
27
+ const filePath = node_path_1.default.join(root, stripped);
28
+ try {
29
+ const content = node_fs_1.default.readFileSync(filePath, 'utf-8');
30
+ res.setHeader('Content-Type', 'application/javascript; charset=utf-8');
31
+ res.end(content);
32
+ }
33
+ catch {
34
+ next();
35
+ }
36
+ });
37
+ },
38
+ };
39
+ }
@@ -10,6 +10,7 @@ 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
+ const raw_jsx_1 = require("./plugins/raw-jsx");
13
14
  const routes_json_1 = require("./plugins/routes-json");
14
15
  const normalize_base_path_1 = require("./normalize-base-path");
15
16
  /**
@@ -49,10 +50,6 @@ function createHtmlViteConfig(opts = {}) {
49
50
  base,
50
51
  appType: 'mpa',
51
52
  clearScreen: false,
52
- // .jsx 走客户端编译,跳过 esbuild 转换,原样 serve 给浏览器
53
- esbuild: {
54
- exclude: /\.jsx$/,
55
- },
56
53
  server: {
57
54
  host,
58
55
  port,
@@ -64,6 +61,7 @@ function createHtmlViteConfig(opts = {}) {
64
61
  : { path: '/ws' },
65
62
  },
66
63
  plugins: [
64
+ (0, raw_jsx_1.rawJsxPlugin)({ root, clientBasePath }),
67
65
  (0, health_1.healthPlugin)(),
68
66
  (0, inject_1.platformInjectPlugin)({ appId }),
69
67
  // dev only:apply:'serve' 自带,build 不挂
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/coding-html-devserver",
3
- "version": "0.1.4",
3
+ "version": "0.1.5-alpha.1",
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",