@evjs/webpack-plugin 0.0.1-rc.13

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/AGENT.md ADDED
@@ -0,0 +1,100 @@
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 `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
+ 5. **Manifest emission** — writes `manifest.json` via `processAssets` hook
42
+
43
+ ### Output
44
+
45
+ ```
46
+ dist/
47
+ ├── client/ # client webpack output
48
+ │ ├── main.[hash].js
49
+ │ └── index.html
50
+ └── server/
51
+ ├── server.js # server bundle (Node.js)
52
+ └── manifest.json # server function registry
53
+ ```
54
+
55
+ ### Manifest Format
56
+
57
+ ```json
58
+ {
59
+ "version": 1,
60
+ "serverFunctions": {
61
+ "abc123:getUsers": {
62
+ "module": "./api/users.server",
63
+ "export": "getUsers"
64
+ }
65
+ }
66
+ }
67
+ ```
68
+
69
+ ## server-fn-loader
70
+
71
+ Webpack loader for `"use server"` files. Automatically detects whether it's running in the client or server compiler and applies the appropriate transform.
72
+
73
+ ```js
74
+ {
75
+ test: /\.server\.(ts|tsx|js|jsx)$/,
76
+ use: [
77
+ { loader: "swc-loader" },
78
+ { loader: "@evjs/webpack-plugin/server-fn-loader" },
79
+ ],
80
+ }
81
+ ```
82
+
83
+ **Client compiler** → replaces function bodies with `__fn_call` RPC stubs
84
+ **Server compiler** → preserves function bodies, appends `registerServerFn()` calls
85
+
86
+ ## Key Files
87
+
88
+ | File | Purpose |
89
+ |------|---------|
90
+ | `src/index.ts` | `EvWebpackPlugin` — main plugin |
91
+ | `src/server-fn-loader.ts` | Webpack loader for `"use server"` transforms |
92
+
93
+ ## Integration with @evjs/cli
94
+
95
+ `@evjs/cli` creates the webpack config in `create-webpack-config.ts`:
96
+
97
+ 1. Adds `EvWebpackPlugin` to plugins
98
+ 2. Adds `server-fn-loader` to module rules (before `swc-loader`)
99
+ 3. Configures dev server proxy for `/api/fn` → API server
100
+ 4. In dev mode, sets `runner` to `"@evjs/runtime/server#serve"` for auto-start
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 `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
+ // Runner — bake into bundle for self-starting dev server
45
+ runner: 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.runner` | `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;AAqBxC,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,149 @@
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
+ entry: this.entry,
14
+ fns: this.fns,
15
+ };
16
+ }
17
+ }
18
+ /**
19
+ * Webpack plugin for the ev framework.
20
+ *
21
+ * Automatically discovers files with the "use server" directive based on the client dependencies
22
+ * and manages the server-side build via a child compiler.
23
+ */
24
+ export class EvWebpackPlugin {
25
+ options;
26
+ constructor(options) {
27
+ this.options = options ?? {};
28
+ }
29
+ apply(compiler) {
30
+ const collector = new ManifestCollector();
31
+ // Attach collector to compiler so the loader can access it
32
+ compiler._ev_manifest_collector = collector;
33
+ // Check if the current compiler is already the Node Child Compiler
34
+ const isServer = compiler.options.name === "evServer" ||
35
+ compiler.options.target === "node";
36
+ if (!isServer) {
37
+ // We are in the Client compiler.
38
+ compiler.hooks.make.tapAsync("EvWebpackPlugin", async (compilation, callback) => {
39
+ compilation.hooks.finishModules.tapAsync("EvWebpackPlugin", (modules, finishCallback) => {
40
+ const serverModulePaths = [];
41
+ for (const module of modules) {
42
+ const resource = "resource" in module ? module.resource : null;
43
+ if (!resource || typeof resource !== "string")
44
+ continue;
45
+ if (resource.includes("node_modules") ||
46
+ !/\.(ts|tsx|js|jsx)$/.test(resource)) {
47
+ continue;
48
+ }
49
+ try {
50
+ const content = fs.readFileSync(resource, "utf-8");
51
+ if (detectUseServer(content)) {
52
+ serverModulePaths.push(resource);
53
+ }
54
+ }
55
+ catch (_err) {
56
+ // Ignore read errors for dynamically generated Webpack modules
57
+ }
58
+ }
59
+ if (serverModulePaths.length === 0) {
60
+ return finishCallback();
61
+ }
62
+ // Generate server entry using build-tools (bundler-agnostic)
63
+ const serverEntryContent = generateServerEntry(this.options.server, serverModulePaths);
64
+ // Use a Data URI as a virtual entry point
65
+ const serverEntryPath = `data:text/javascript,${encodeURIComponent(serverEntryContent)}`;
66
+ // Spawn the Node Server child compiler (webpack-specific)
67
+ const isProduction = compiler.options.mode === "production";
68
+ const outputOptions = {
69
+ filename: isProduction
70
+ ? "../server/main.[contenthash:8].js"
71
+ : "../server/main.js",
72
+ library: { type: "commonjs2" },
73
+ chunkFormat: "commonjs",
74
+ };
75
+ const childCompiler = compilation.createChildCompiler("evServer", outputOptions, [
76
+ new compiler.webpack.node.NodeTemplatePlugin({
77
+ asyncChunkLoading: false,
78
+ }),
79
+ new compiler.webpack.node.NodeTargetPlugin(),
80
+ new compiler.webpack.library.EnableLibraryPlugin("commonjs2"),
81
+ new compiler.webpack.ExternalsPlugin("commonjs", [
82
+ ({ request }, cb) => {
83
+ if (!request || typeof request !== "string") {
84
+ return cb();
85
+ }
86
+ // Externalize Node builtins
87
+ if (request.startsWith("node:") ||
88
+ builtinModules.includes(request)) {
89
+ return cb(null, request);
90
+ }
91
+ // Never externalize relative, absolute, data-uri,
92
+ // or @evjs/* imports (workspace ESM packages that
93
+ // must be bundled into the CJS server output).
94
+ if (request.startsWith(".") ||
95
+ request.startsWith("/") ||
96
+ request.startsWith("data:") ||
97
+ request.startsWith("@evjs/")) {
98
+ return cb();
99
+ }
100
+ // Externalize all other bare-specifier imports
101
+ // (third-party node_modules). This is essential for
102
+ // native addons (e.g. better-sqlite3) whose .node
103
+ // binaries cannot be bundled by webpack.
104
+ cb(null, request);
105
+ },
106
+ ]),
107
+ new compiler.webpack.EntryPlugin(compiler.context, serverEntryPath, { name: "main" }),
108
+ ]);
109
+ childCompiler._ev_manifest_collector = collector;
110
+ childCompiler.runAsChild((err, _entries, childCompilation) => {
111
+ if (err)
112
+ return finishCallback(err);
113
+ if (childCompilation?.errors &&
114
+ childCompilation.errors.length > 0) {
115
+ return finishCallback(childCompilation.errors[0]);
116
+ }
117
+ // Store the hashed entry filename on the collector
118
+ // so it gets merged into manifest.json by processAssets
119
+ if (childCompilation) {
120
+ for (const [, entry] of childCompilation.entrypoints) {
121
+ const files = entry.getFiles();
122
+ if (files.length > 0) {
123
+ collector.entry = files[0].replace(/^\.\.\/server\//, "");
124
+ }
125
+ }
126
+ }
127
+ finishCallback();
128
+ });
129
+ });
130
+ callback();
131
+ });
132
+ }
133
+ // Emit manifest using modern processAssets hook
134
+ compiler.hooks.thisCompilation.tap("EvWebpackPlugin", (compilation) => {
135
+ compilation.hooks.processAssets.tap({
136
+ name: "EvWebpackPlugin",
137
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
138
+ }, () => {
139
+ const manifest = collector.getManifest();
140
+ if (Object.keys(manifest.fns).length === 0) {
141
+ return;
142
+ }
143
+ const content = JSON.stringify(manifest, null, 2);
144
+ compilation.emitAsset("../server/manifest.json", new compiler.webpack.sources.RawSource(content));
145
+ });
146
+ });
147
+ }
148
+ }
149
+ //# 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,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,CAAC;IACJ,CAAC;CACF;AAUD;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IAClB,OAAO,CAAyB;IAExC,YAAY,OAAgC;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;IAC/B,CAAC;IACD,KAAK,CAAC,QAAkB;QACtB,MAAM,SAAS,GAAG,IAAI,iBAAiB,EAAE,CAAC;QAE1C,2DAA2D;QAC1D,QAAuB,CAAC,sBAAsB,GAAG,SAAS,CAAC;QAE5D,mEAAmE;QACnE,MAAM,QAAQ,GACZ,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,UAAU;YACpC,Q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;4BACH,CAAC;wBACH,CAAC;wBAED,cAAc,EAAE,CAAC;oBACnB,CAAC,CAAC,CAAC;gBACL,CAAC,CACF,CAAC;gBACF,QAAQ,EAAE,CAAC;YACb,CAAC,CACF,CAAC;QACJ,CAAC;QAED,gDAAgD;QAChD,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC,WAAW,EAAE,EAAE;YACpE,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CACjC;gBACE,IAAI,EAAE,iBAAiB;gBACvB,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,8BAA8B;aACnE,EACD,GAAG,EAAE;gBACH,MAAM,QAAQ,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;gBACzC,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBAC3C,OAAO;gBACT,CAAC;gBACD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;gBAElD,WAAW,CAAC,SAAS,CACnB,yBAAyB,EACzB,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAChD,CAAC;YACJ,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,23 @@
1
+ import type { Compiler } from "webpack";
2
+ interface LoaderContext {
3
+ getOptions(): {
4
+ isServer?: boolean;
5
+ };
6
+ resourcePath: string;
7
+ rootContext: string;
8
+ _compiler?: Compiler & {
9
+ _ev_manifest_collector?: {
10
+ addServerFn(id: string, meta: {
11
+ moduleId: string;
12
+ export: string;
13
+ }): void;
14
+ };
15
+ };
16
+ }
17
+ /**
18
+ * Webpack loader for "use server" files.
19
+ * Thin wrapper that delegates to @evjs/build-tools for the actual transformation.
20
+ */
21
+ export default function serverFnLoader(this: LoaderContext, source: string): Promise<string>;
22
+ export {};
23
+ //# 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,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,MAAM,CAAC,CAmBjB"}
@@ -0,0 +1,24 @@
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 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";
13
+ }
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
+ }
24
+ //# 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;AAcxD;;;GAGG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,cAAc,CAE1C,MAAc;IAEd,MAAM,eAAe,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC;IAChD,IAAI,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;IACxC,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACpC,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC;QAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC;QAC/C,QAAQ,GAAG,YAAY,KAAK,UAAU,IAAI,MAAM,KAAK,MAAM,CAAC;IAC9D,CAAC;IAED,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,EAAE,sBAAsB,CAAC;IAEjE,OAAO,mBAAmB,CAAC,MAAM,EAAE;QACjC,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,UAAU,EAAE,iBAAiB;YAC3B,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC;YAC3D,CAAC,CAAC,SAAS;KACd,CAAC,CAAC;AACL,CAAC"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@evjs/webpack-plugin",
3
+ "version": "0.0.1-rc.13",
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
+ "AGENT.md"
28
+ ],
29
+ "keywords": [
30
+ "evjs",
31
+ "webpack",
32
+ "plugin",
33
+ "loader",
34
+ "server-functions"
35
+ ],
36
+ "author": "xusd320",
37
+ "license": "MIT",
38
+ "dependencies": {
39
+ "@evjs/build-tools": "0.0.1-rc.13",
40
+ "@evjs/manifest": "0.0.1-rc.13"
41
+ },
42
+ "devDependencies": {
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
+ }