@evjs/webpack-plugin 0.0.0

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 ADDED
@@ -0,0 +1,74 @@
1
+ # @evjs/webpack-plugin
2
+
3
+ Webpack adapter for the **ev** framework. Thin wrapper over [`@evjs/build-tools`](../build-tools) that connects bundler-agnostic build logic to Webpack's plugin and loader APIs.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @evjs/webpack-plugin
9
+ ```
10
+
11
+ ## Exports
12
+
13
+ | Export | Description |
14
+ |--------|-------------|
15
+ | `EvWebpackPlugin` | Plugin that auto-discovers `"use server"` files and manages server builds |
16
+ | `server-fn-loader` | Loader that transforms `"use server"` files for client/server |
17
+
18
+ ## How It Works
19
+
20
+ ### EvWebpackPlugin
21
+
22
+ 1. **Scans client modules** for `"use server"` files via `detectUseServer()` from build-tools.
23
+ 2. **Generates a server entry** via `generateServerEntry()` — produces a virtual data-URI module.
24
+ 3. **Spawns a child compiler** targeting Node.js — builds the server bundle alongside the client.
25
+ 4. **Emits `dist/manifest.json`** mapping function IDs to their module and export names.
26
+
27
+ ### server-fn-loader
28
+
29
+ Auto-detects whether it's running in the client or server compiler and delegates to `transformServerFile()`:
30
+ - **Client compiler** → replaces function bodies with RPC stubs.
31
+ - **Server compiler** → keeps original source, appends registrations, and reports to the manifest.
32
+
33
+ ## Usage
34
+
35
+ ```js
36
+ const { EvWebpackPlugin } = require("@evjs/webpack-plugin");
37
+
38
+ module.exports = {
39
+ plugins: [
40
+ new EvWebpackPlugin({
41
+ server: {
42
+ // App factory (default: "@evjs/runtime/server#createApp")
43
+ appFactory: "@evjs/runtime/server#createApp",
44
+ // Backend — bake into bundle for self-starting dev server
45
+ backend: process.env.NODE_ENV === "development"
46
+ ? "@evjs/runtime/server#serve"
47
+ : undefined,
48
+ // Extra imports (middleware, config, etc.)
49
+ setup: [],
50
+ },
51
+ }),
52
+ ],
53
+ module: {
54
+ rules: [
55
+ {
56
+ test: /\.tsx?$/,
57
+ exclude: /node_modules/,
58
+ use: [
59
+ { loader: "swc-loader" },
60
+ { loader: "@evjs/webpack-plugin/server-fn-loader" },
61
+ ],
62
+ },
63
+ ],
64
+ },
65
+ };
66
+ ```
67
+
68
+ ### Plugin Options
69
+
70
+ | Option | Type | Default | Description |
71
+ |--------|------|---------|-------------|
72
+ | `server.appFactory` | `string` | `"@evjs/runtime/server#createApp"` | Module ref for app factory |
73
+ | `server.backend` | `string?` | `undefined` | Module ref for auto-starting the server |
74
+ | `server.setup` | `string[]` | `[]` | Extra imports to prepend to server entry |
package/esm/index.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { type ServerEntryConfig } from "@evjs/build-tools";
2
+ import type { Compiler } from "webpack";
3
+ export type { ServerEntryConfig };
4
+ export interface EvWebpackPluginOptions {
5
+ server?: ServerEntryConfig;
6
+ }
7
+ /**
8
+ * Webpack plugin for the ev framework.
9
+ *
10
+ * Automatically discovers files with the "use server" directive based on the client dependencies
11
+ * and manages the server-side build via a child compiler.
12
+ */
13
+ export declare class EvWebpackPlugin {
14
+ private options;
15
+ constructor(options?: EvWebpackPluginOptions);
16
+ apply(compiler: Compiler): void;
17
+ }
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAuBxC,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAElC,MAAM,WAAW,sBAAsB;IACrC,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC5B;AAED;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAyB;gBAE5B,OAAO,CAAC,EAAE,sBAAsB;IAG5C,KAAK,CAAC,QAAQ,EAAE,QAAQ;CA2KzB"}
package/esm/index.js ADDED
@@ -0,0 +1,151 @@
1
+ import fs from "node:fs";
2
+ import { builtinModules } from "node:module";
3
+ import { detectUseServer, generateServerEntry, } from "@evjs/build-tools";
4
+ class ManifestCollector {
5
+ fns = {};
6
+ entry = "main.js";
7
+ addServerFn(id, meta) {
8
+ this.fns[id] = meta;
9
+ }
10
+ getManifest() {
11
+ return {
12
+ version: 1,
13
+ server: {
14
+ entry: this.entry,
15
+ fns: this.fns,
16
+ },
17
+ };
18
+ }
19
+ }
20
+ /**
21
+ * Webpack plugin for the ev framework.
22
+ *
23
+ * Automatically discovers files with the "use server" directive based on the client dependencies
24
+ * and manages the server-side build via a child compiler.
25
+ */
26
+ export class EvWebpackPlugin {
27
+ options;
28
+ constructor(options) {
29
+ this.options = options ?? {};
30
+ }
31
+ apply(compiler) {
32
+ const collector = new ManifestCollector();
33
+ // Attach collector to compiler so the loader can access it
34
+ compiler._ev_manifest_collector = collector;
35
+ // Check if the current compiler is already the Node Child Compiler
36
+ const isServer = compiler.options.name === "evServer" ||
37
+ compiler.options.target === "node";
38
+ if (!isServer) {
39
+ // We are in the Client compiler.
40
+ compiler.hooks.make.tapAsync("EvWebpackPlugin", async (compilation, callback) => {
41
+ compilation.hooks.finishModules.tapAsync("EvWebpackPlugin", (modules, finishCallback) => {
42
+ const serverModulePaths = [];
43
+ for (const module of modules) {
44
+ const resource = "resource" in module ? module.resource : null;
45
+ if (!resource || typeof resource !== "string")
46
+ continue;
47
+ if (resource.includes("node_modules") ||
48
+ !/\.(ts|tsx|js|jsx)$/.test(resource)) {
49
+ continue;
50
+ }
51
+ try {
52
+ const content = fs.readFileSync(resource, "utf-8");
53
+ if (detectUseServer(content)) {
54
+ serverModulePaths.push(resource);
55
+ }
56
+ }
57
+ catch (_err) {
58
+ // Ignore read errors for dynamically generated Webpack modules
59
+ }
60
+ }
61
+ if (serverModulePaths.length === 0) {
62
+ return finishCallback();
63
+ }
64
+ // Generate server entry using build-tools (bundler-agnostic)
65
+ const serverEntryContent = generateServerEntry(this.options.server, serverModulePaths);
66
+ // Use a Data URI as a virtual entry point
67
+ const serverEntryPath = `data:text/javascript,${encodeURIComponent(serverEntryContent)}`;
68
+ // Spawn the Node Server child compiler (webpack-specific)
69
+ const isProduction = compiler.options.mode === "production";
70
+ const outputOptions = {
71
+ filename: isProduction
72
+ ? "../server/main.[contenthash:8].js"
73
+ : "../server/main.js",
74
+ library: { type: "commonjs2" },
75
+ chunkFormat: "commonjs",
76
+ };
77
+ const childCompiler = compilation.createChildCompiler("evServer", outputOptions, [
78
+ new compiler.webpack.node.NodeTemplatePlugin({
79
+ asyncChunkLoading: false,
80
+ }),
81
+ new compiler.webpack.node.NodeTargetPlugin(),
82
+ new compiler.webpack.library.EnableLibraryPlugin("commonjs2"),
83
+ new compiler.webpack.ExternalsPlugin("commonjs", [
84
+ ({ request }, cb) => {
85
+ if (!request || typeof request !== "string") {
86
+ return cb();
87
+ }
88
+ // Externalize Node builtins
89
+ if (request.startsWith("node:") ||
90
+ builtinModules.includes(request)) {
91
+ return cb(null, request);
92
+ }
93
+ // Never externalize relative, absolute, data-uri,
94
+ // or @evjs/* imports (workspace ESM packages that
95
+ // must be bundled into the CJS server output).
96
+ if (request.startsWith(".") ||
97
+ request.startsWith("/") ||
98
+ request.startsWith("data:") ||
99
+ request.startsWith("@evjs/")) {
100
+ return cb();
101
+ }
102
+ // Externalize all other bare-specifier imports
103
+ // (third-party node_modules). This is essential for
104
+ // native addons (e.g. better-sqlite3) whose .node
105
+ // binaries cannot be bundled by webpack.
106
+ cb(null, request);
107
+ },
108
+ ]),
109
+ new compiler.webpack.EntryPlugin(compiler.context, serverEntryPath, { name: "main" }),
110
+ ]);
111
+ childCompiler._ev_manifest_collector = collector;
112
+ childCompiler.runAsChild((err, _entries, childCompilation) => {
113
+ if (err)
114
+ return finishCallback(err);
115
+ if (childCompilation?.errors &&
116
+ childCompilation.errors.length > 0) {
117
+ return finishCallback(childCompilation.errors[0]);
118
+ }
119
+ // Store the hashed entry filename on the collector
120
+ // so it gets merged into manifest.json by processAssets
121
+ if (childCompilation) {
122
+ for (const [, entry] of childCompilation.entrypoints) {
123
+ const files = entry.getFiles();
124
+ if (files.length > 0) {
125
+ collector.entry = files[0].replace(/^\.\.\/server\//, "");
126
+ }
127
+ }
128
+ }
129
+ finishCallback();
130
+ });
131
+ });
132
+ callback();
133
+ });
134
+ }
135
+ // Emit manifest using modern processAssets hook
136
+ compiler.hooks.thisCompilation.tap("EvWebpackPlugin", (compilation) => {
137
+ compilation.hooks.processAssets.tap({
138
+ name: "EvWebpackPlugin",
139
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
140
+ }, () => {
141
+ const manifest = collector.getManifest();
142
+ if (Object.keys(manifest.server.fns).length === 0) {
143
+ return;
144
+ }
145
+ const content = JSON.stringify(manifest, null, 2);
146
+ compilation.emitAsset("../manifest.json", new compiler.webpack.sources.RawSource(content));
147
+ });
148
+ });
149
+ }
150
+ }
151
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EACL,eAAe,EACf,mBAAmB,GAEpB,MAAM,mBAAmB,CAAC;AAI3B,MAAM,iBAAiB;IACrB,GAAG,GAAkC,EAAE,CAAC;IACxC,KAAK,GAAW,SAAS,CAAC;IAE1B,WAAW,CAAC,EAAU,EAAE,IAAmB;QACzC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,WAAW;QACT,OAAO;YACL,OAAO,EAAE,CAAC;YACV,MAAM,EAAE;gBACN,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,GAAG,EAAE,IAAI,CAAC,GAAG;aACd;SACF,CAAC;IACJ,CAAC;CACF;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CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ import type { Compiler } from "webpack";
2
+ interface LoaderContext {
3
+ async(): (err: Error | null, result?: string, sourceMap?: any) => void;
4
+ getOptions(): {
5
+ isServer?: boolean;
6
+ };
7
+ resourcePath: string;
8
+ rootContext: string;
9
+ _compiler?: Compiler & {
10
+ _ev_manifest_collector?: {
11
+ addServerFn(id: string, meta: {
12
+ moduleId: string;
13
+ export: string;
14
+ }): void;
15
+ };
16
+ };
17
+ }
18
+ /**
19
+ * Webpack loader for "use server" files.
20
+ * Thin wrapper that delegates to @evjs/build-tools for the actual transformation.
21
+ */
22
+ export default function serverFnLoader(this: LoaderContext, source: string): Promise<void>;
23
+ export {};
24
+ //# sourceMappingURL=server-fn-loader.d.ts.map
@@ -0,0 +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,UAAU,aAAa;IACrB,KAAK,IAAI,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IACvE,UAAU,IAAI;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,QAAQ,GAAG;QACrB,sBAAsB,CAAC,EAAE;YACvB,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;gBAAE,QAAQ,EAAE,MAAM,CAAC;gBAAC,MAAM,EAAE,MAAM,CAAA;aAAE,GAAG,IAAI,CAAC;SAC3E,CAAC;KACH,CAAC;CACH;AAED;;;GAGG;AACH,wBAA8B,cAAc,CAC1C,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CA2Bf"}
@@ -0,0 +1,32 @@
1
+ import { transformServerFile } from "@evjs/build-tools";
2
+ /**
3
+ * Webpack loader for "use server" files.
4
+ * Thin wrapper that delegates to @evjs/build-tools for the actual transformation.
5
+ */
6
+ export default async function serverFnLoader(source) {
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);
30
+ }
31
+ }
32
+ //# sourceMappingURL=server-fn-loader.js.map
@@ -0,0 +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;AAexD;;;GAGG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,cAAc,CAE1C,MAAc;IAEd,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IAC9B,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC;QAChD,IAAI,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;QACxC,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,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 ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@evjs/webpack-plugin",
3
+ "version": "0.0.0",
4
+ "description": "Webpack plugin and loaders for the ev framework",
5
+ "type": "module",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "main": "./esm/index.js",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./esm/index.d.ts",
13
+ "import": "./esm/index.js",
14
+ "require": "./esm/index.js"
15
+ },
16
+ "./server-fn-loader": {
17
+ "types": "./esm/server-fn-loader.d.ts",
18
+ "default": "./esm/server-fn-loader.js"
19
+ }
20
+ },
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "check-types": "tsc --noEmit"
24
+ },
25
+ "files": [
26
+ "esm"
27
+ ],
28
+ "keywords": [
29
+ "evjs",
30
+ "webpack",
31
+ "plugin",
32
+ "loader",
33
+ "server-functions"
34
+ ],
35
+ "author": "xusd320",
36
+ "license": "MIT",
37
+ "dependencies": {
38
+ "@evjs/build-tools": "*",
39
+ "@evjs/manifest": "*"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^22.13.5",
43
+ "typescript": "^5.7.3",
44
+ "webpack": "^5.105.4"
45
+ },
46
+ "homepage": "https://github.com/evaijs/evjs#readme",
47
+ "bugs": {
48
+ "url": "https://github.com/evaijs/evjs/issues"
49
+ },
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/evaijs/evjs.git"
53
+ }
54
+ }