@evjs/webpack-plugin 0.0.1-rc.15 → 0.0.1-rc.17

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 CHANGED
@@ -41,8 +41,8 @@ module.exports = {
41
41
  server: {
42
42
  // App factory (default: "@evjs/runtime/server#createApp")
43
43
  appFactory: "@evjs/runtime/server#createApp",
44
- // Runner — bake into bundle for self-starting dev server
45
- runner: process.env.NODE_ENV === "development"
44
+ // Backend — bake into bundle for self-starting dev server
45
+ backend: process.env.NODE_ENV === "development"
46
46
  ? "@evjs/runtime/server#serve"
47
47
  : undefined,
48
48
  // Extra imports (middleware, config, etc.)
@@ -70,5 +70,5 @@ module.exports = {
70
70
  | Option | Type | Default | Description |
71
71
  |--------|------|---------|-------------|
72
72
  | `server.appFactory` | `string` | `"@evjs/runtime/server#createApp"` | Module ref for app factory |
73
- | `server.runner` | `string?` | `undefined` | Module ref for auto-starting the server |
73
+ | `server.backend` | `string?` | `undefined` | Module ref for auto-starting the server |
74
74
  | `server.setup` | `string[]` | `[]` | Extra imports to prepend to server entry |
@@ -1,5 +1,6 @@
1
1
  import type { Compiler } from "webpack";
2
2
  interface LoaderContext {
3
+ async(): (err: Error | null, result?: string, sourceMap?: unknown) => void;
3
4
  getOptions(): {
4
5
  isServer?: boolean;
5
6
  };
@@ -18,6 +19,6 @@ interface LoaderContext {
18
19
  * Webpack loader for "use server" files.
19
20
  * Thin wrapper that delegates to @evjs/build-tools for the actual transformation.
20
21
  */
21
- export default function serverFnLoader(this: LoaderContext, source: string): Promise<string>;
22
+ export default function serverFnLoader(this: LoaderContext, source: string): Promise<void>;
22
23
  export {};
23
24
  //# sourceMappingURL=server-fn-loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server-fn-loader.d.ts","sourceRoot":"","sources":["../src/server-fn-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,U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O,CAAC,IAAI,CAAC,CA2Bf"}
@@ -4,21 +4,29 @@ import { transformServerFile } from "@evjs/build-tools";
4
4
  * Thin wrapper that delegates to @evjs/build-tools for the actual transformation.
5
5
  */
6
6
  export default async function serverFnLoader(source) {
7
- const explicitOptions = this.getOptions() || {};
8
- let isServer = explicitOptions.isServer;
9
- if (typeof isServer === "undefined") {
10
- const compilerName = this._compiler?.name;
11
- const target = this._compiler?.options?.target;
12
- isServer = compilerName === "evServer" || target === "node";
7
+ const callback = this.async();
8
+ try {
9
+ const explicitOptions = this.getOptions() || {};
10
+ let isServer = explicitOptions.isServer;
11
+ if (typeof isServer === "undefined") {
12
+ const compilerName = this._compiler?.name;
13
+ const target = this._compiler?.options?.target;
14
+ isServer = compilerName === "evServer" || target === "node";
15
+ }
16
+ const manifestCollector = this._compiler?._ev_manifest_collector;
17
+ const result = await transformServerFile(source, {
18
+ resourcePath: this.resourcePath,
19
+ rootContext: this.rootContext,
20
+ isServer: !!isServer,
21
+ onServerFn: manifestCollector
22
+ ? (fnId, meta) => manifestCollector.addServerFn(fnId, meta)
23
+ : undefined,
24
+ });
25
+ const map = result.map ? JSON.parse(result.map) : undefined;
26
+ callback(null, result.code, map);
27
+ }
28
+ catch (err) {
29
+ callback(err);
13
30
  }
14
- const manifestCollector = this._compiler?._ev_manifest_collector;
15
- return transformServerFile(source, {
16
- resourcePath: this.resourcePath,
17
- rootContext: this.rootContext,
18
- isServer: !!isServer,
19
- onServerFn: manifestCollector
20
- ? (fnId, meta) => manifestCollector.addServerFn(fnId, meta)
21
- : undefined,
22
- });
23
31
  }
24
32
  //# sourceMappingURL=server-fn-loader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server-fn-loader.js","sourceRoot":"","sources":["../src/server-fn-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAcxD;;;GAGG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,cAAc,CAE1C,MA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CAAC;YACpC,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC;YAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC;YAC/C,QAAQ,GAAG,YAAY,KAAK,UAAU,IAAI,MAAM,KAAK,MAAM,CAAC;QAC9D,CAAC;QAED,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,EAAE,sBAAsB,CAAC;QAEjE,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,MAAM,EAAE;YAC/C,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,UAAU,EAAE,iBAAiB;gBAC3B,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC;gBAC3D,CAAC,CAAC,SAAS;SACd,CAAC,CAAC;QAEH,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,QAAQ,CAAC,GAAY,CAAC,CAAC;IACzB,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evjs/webpack-plugin",
3
- "version": "0.0.1-rc.15",
3
+ "version": "0.0.1-rc.17",
4
4
  "description": "Webpack plugin and loaders for the ev framework",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -23,8 +23,7 @@
23
23
  "check-types": "tsc --noEmit"
24
24
  },
25
25
  "files": [
26
- "esm",
27
- "AGENT.md"
26
+ "esm"
28
27
  ],
29
28
  "keywords": [
30
29
  "evjs",
@@ -36,10 +35,11 @@
36
35
  "author": "xusd320",
37
36
  "license": "MIT",
38
37
  "dependencies": {
39
- "@evjs/build-tools": "0.0.1-rc.15",
40
- "@evjs/manifest": "0.0.1-rc.15"
38
+ "@evjs/build-tools": "*",
39
+ "@evjs/manifest": "*"
41
40
  },
42
41
  "devDependencies": {
42
+ "@types/node": "^22.13.5",
43
43
  "typescript": "^5.7.3",
44
44
  "webpack": "^5.105.4"
45
45
  },
package/AGENT.md DELETED
@@ -1,104 +0,0 @@
1
- # @evjs/webpack-plugin — Agent Guide
2
-
3
- > AI-agent reference for the `@evjs/webpack-plugin` package. This is an internal package used by `@evjs/cli` — application developers don't configure it directly.
4
-
5
- ## Overview
6
-
7
- Webpack adapter wrapping `@evjs/build-tools`. Provides:
8
- 1. **`EvWebpackPlugin`** — webpack plugin for server function discovery + child compilation
9
- 2. **`server-fn-loader`** — webpack loader for `"use server"` file transforms
10
-
11
- ## EvWebpackPlugin
12
-
13
- Auto-discovers `"use server"` files, generates server entry, spawns a server-targeted child compiler, and emits `dist/manifest.json`.
14
-
15
- ```js
16
- const { EvWebpackPlugin } = require("@evjs/webpack-plugin");
17
-
18
- new EvWebpackPlugin({
19
- server: {
20
- appFactory: "@evjs/runtime/server#createApp", // default
21
- runner: "@evjs/runtime/server#serve", // for self-starting servers
22
- middleware: ["./src/middleware/auth#default"], // middleware imports
23
- },
24
- });
25
- ```
26
-
27
- ### Options
28
-
29
- | Option | Type | Default | Description |
30
- |--------|------|---------|-------------|
31
- | `server.appFactory` | `string` | `"@evjs/runtime/server#createApp"` | Hono app factory module ref |
32
- | `server.runner` | `string?` | `undefined` | Runner module ref (e.g., `"@evjs/runtime/server#serve"`) |
33
- | `server.middleware` | `string[]` | `[]` | Middleware module refs prepended to server entry |
34
-
35
- ### What It Does (Build Pipeline)
36
-
37
- 1. **Discovery** — globs for `*.server.{ts,js,tsx,jsx}` in source tree
38
- 2. **Client transform** — `server-fn-loader` replaces function bodies with `__fn_call` stubs
39
- 3. **Server entry generation** — calls `generateServerEntry()` from `@evjs/build-tools`
40
- 4. **Child compiler** — spawns a webpack child compilation targeting `node` with the server entry
41
- - **Externals**: all third-party `node_modules` are externalized (essential for native addons like `better-sqlite3`); `@evjs/*` packages are bundled into the CJS output
42
- 5. **Manifest emission** — writes `dist/manifest.json` via `processAssets` hook
43
-
44
- ### Output
45
-
46
- ```
47
- dist/
48
- ├── client/ # client webpack output
49
- │ ├── main.[hash].js
50
- │ └── index.html
51
- ├── manifest.json # unified manifest (server + client)
52
- └── server/
53
- └── main.[hash].js # server bundle (Node.js)
54
- ```
55
-
56
- ### Manifest Format
57
-
58
- ```json
59
- {
60
- "version": 1,
61
- "server": {
62
- "entry": "main.a1b2c3d4.js",
63
- "fns": {
64
- "abc123:getUsers": {
65
- "moduleId": "./api/users.server",
66
- "export": "getUsers"
67
- }
68
- }
69
- }
70
- }
71
- ```
72
-
73
- ## server-fn-loader
74
-
75
- Webpack loader for `"use server"` files. Automatically detects whether it's running in the client or server compiler and applies the appropriate transform.
76
-
77
- ```js
78
- {
79
- test: /\.server\.(ts|tsx|js|jsx)$/,
80
- use: [
81
- { loader: "swc-loader" },
82
- { loader: "@evjs/webpack-plugin/server-fn-loader" },
83
- ],
84
- }
85
- ```
86
-
87
- **Client compiler** → replaces function bodies with `__fn_call` RPC stubs
88
- **Server compiler** → preserves function bodies, appends `registerServerFn()` calls
89
-
90
- ## Key Files
91
-
92
- | File | Purpose |
93
- |------|---------|
94
- | `src/index.ts` | `EvWebpackPlugin` — main plugin |
95
- | `src/server-fn-loader.ts` | Webpack loader for `"use server"` transforms |
96
-
97
- ## Integration with @evjs/cli
98
-
99
- `@evjs/cli` creates the webpack config in `create-webpack-config.ts`:
100
-
101
- 1. Adds `EvWebpackPlugin` to plugins
102
- 2. Adds `server-fn-loader` to module rules (before `swc-loader`)
103
- 3. Configures dev server proxy for `/api/fn` → API server
104
- 4. In dev mode, sets `runner` to `"@evjs/runtime/server#serve"` for auto-start