-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.mts
More file actions
82 lines (80 loc) · 3.99 KB
/
vite.config.mts
File metadata and controls
82 lines (80 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import path from 'node:path';
import { defineConfig, Plugin } from 'vite';
// Vite plugin: replace @aigne/core/dist/loader/agent-js with a safe stub.
// The original file contains `new Function("path", "return import(path)")`.
// In QuickJS (non-module eval mode) this throws SyntaxError at parse time,
// which aborts the entire IIFE before globalThis.__invoke is defined.
function stubAgentJsDynamicImport(): Plugin {
return {
name: 'stub-agent-js-dynamic-import',
load(id: string) {
if (id.includes('@aigne/core') && id.includes('loader/agent-js')) {
return `export async function loadAgentFromJsFile(path) {
throw new Error('[QuickJS] Dynamic import not supported in native runtime: ' + path);
}
`;
}
},
};
}
export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, 'src/bootstrap.ts'),
formats: ['iife'],
name: 'AigneRuntime',
fileName: 'aigne-runtime-jscore',
},
outDir: path.resolve(__dirname, 'dist'),
target: 'es2020',
minify: false,
sourcemap: 'inline',
},
resolve: {
alias: {
// @aigne/core 依赖的 platform-helpers stub
'@aigne/platform-helpers/nodejs/index.js': path.resolve(
__dirname,
'./src/polyfills/platform-helpers.ts'
),
// @aigne/afs 引用的 Node.js 内置模块
'node:path': path.resolve(__dirname, './src/polyfills/node-path.ts'),
'node:fs/promises': path.resolve(__dirname, './src/polyfills/empty.ts'),
// @aigne/afs-history → @aigne/sqlite → sqlocal(IIFE 不兼容 worker code-splitting)
'@aigne/sqlite': path.resolve(__dirname, './src/polyfills/aigne-sqlite-stub.ts'),
sqlocal: path.resolve(__dirname, './src/polyfills/empty.ts'),
'sqlocal/drizzle': path.resolve(__dirname, './src/polyfills/empty.ts'),
// @aigne/core → @opentelemetry/api(observability,不需要)
'@opentelemetry/api': path.resolve(__dirname, './src/polyfills/opentelemetry-stub.ts'),
// @aigne/core → @modelcontextprotocol/sdk(MCP,不需要)
'@modelcontextprotocol/sdk/client/index.js': path.resolve(__dirname, './src/polyfills/mcp-stub.ts'),
'@modelcontextprotocol/sdk/client/sse.js': path.resolve(__dirname, './src/polyfills/mcp-stub.ts'),
'@modelcontextprotocol/sdk/client/streamableHttp.js': path.resolve(__dirname, './src/polyfills/mcp-stub.ts'),
'@modelcontextprotocol/sdk/client/stdio.js': path.resolve(__dirname, './src/polyfills/mcp-stub.ts'),
'@modelcontextprotocol/sdk/shared/uriTemplate.js': path.resolve(__dirname, './src/polyfills/mcp-stub.ts'),
'@modelcontextprotocol/sdk/types.js': path.resolve(__dirname, './src/polyfills/mcp-stub.ts'),
'@modelcontextprotocol/sdk/shared/protocol.js': path.resolve(__dirname, './src/polyfills/mcp-stub.ts'),
'@modelcontextprotocol/sdk/shared/transport.js': path.resolve(__dirname, './src/polyfills/mcp-stub.ts'),
// Node.js 模块 stub
'fs/promises': path.resolve(__dirname, './src/polyfills/empty.ts'),
stream: path.resolve(__dirname, './src/polyfills/empty.ts'),
http: path.resolve(__dirname, './src/polyfills/empty.ts'),
https: path.resolve(__dirname, './src/polyfills/empty.ts'),
http2: path.resolve(__dirname, './src/polyfills/empty.ts'),
net: path.resolve(__dirname, './src/polyfills/empty.ts'),
tls: path.resolve(__dirname, './src/polyfills/empty.ts'),
os: path.resolve(__dirname, './src/polyfills/empty.ts'),
'node:os': path.resolve(__dirname, './src/polyfills/empty.ts'),
'node:assert': path.resolve(__dirname, './src/polyfills/empty.ts'),
'@smithy/node-http-handler': path.resolve(__dirname, './src/polyfills/empty.ts'),
'https-proxy-agent': path.resolve(__dirname, './src/polyfills/empty.ts'),
'agent-base': path.resolve(__dirname, './src/polyfills/empty.ts'),
},
conditions: ['browser', 'import', 'module', 'default'],
},
plugins: [stubAgentJsDynamicImport()],
define: {
'process.env': JSON.stringify({}),
process: undefined,
},
});