-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
137 lines (132 loc) · 3.34 KB
/
vite.config.ts
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { defineConfig } from "vite";
import { nodePolyfills } from "vite-plugin-node-polyfills";
import type { OutputChunk, OutputAsset } from "rollup";
import path from "path";
import dynamicImportVars from "@rollup/plugin-dynamic-import-vars";
// Custom plugin to add shebang
function addShebangPlugin() {
return {
name: "add-shebang",
generateBundle(
options: any,
bundle: { [fileName: string]: OutputChunk | OutputAsset }
) {
// Find the main entry point
const mainEntry = Object.values(bundle).find(
(chunk): chunk is OutputChunk => chunk.type === "chunk" && chunk.isEntry
);
if (mainEntry) {
mainEntry.code = `#!/usr/bin/env node\n${mainEntry.code}`;
}
},
};
}
// Plugin to handle window references in Node.js
function handleWindowPlugin() {
return {
name: 'handle-window',
transform(code) {
// Replace window.dispatchEvent with a no-op in Node environment
return {
code: code.replace(
/window\.dispatchEvent\(e\)/g,
'typeof window !== "undefined" && window.dispatchEvent(e)'
),
map: null
};
}
};
}
const generatedIndexPath = path.resolve(
__dirname,
`${process.env.VITE_OUTPUT_DIR}/index.ts`
);
const inputFiles = {
"cli": "./src/cli.ts",
"runtime/index": "./src/runtime/index.ts"
};
export default defineConfig(({ mode }) => {
return {
define: {
"process.env.GENERATED_OUTPUT_DIR": JSON.stringify(
process.env.GENERATED_OUTPUT_DIR
),
global: "globalThis",
},
plugins: [
nodePolyfills({
protocolImports: true,
}),
addShebangPlugin(),
handleWindowPlugin(),
dynamicImportVars({
warnOnError: true,
include: ['./src/generated/*.js']
})
// dynamicImport({
// loose: true,
// filter(id) {
// if (id.includes("@modelcontextprotocol/sdk")) {
// return true;
// }
// },
// }),
],
build: {
outDir: "./dist",
rollupOptions: {
input: inputFiles,
output: {
format: "es",
entryFileNames: "[name].js",
chunkFileNames: "chunks/[name]-[hash].js",
},
external: [
"@modelcontextprotocol/sdk",
"@modelcontextprotocol",
"@redocly",
"@ianvs/prettier-plugin-sort-imports",
"prettier-plugin-packagejson",
"ts-morph",
"zod",
"fs",
"path",
"node:perf_hooks",
"yaml",
"openapi-typescript",
"remeda",
"prettier",
"express",
"async_hooks",
"commander",
"node-stdlib-browser",
"detect-port",
"crypto",
"stream",
"http",
"https",
"url",
"os",
"node:crypto",
"node:stream",
"node:http",
"node:https",
"node:url",
"node:os",
"node-stdlib-browser",
"child_process",
],
},
sourcemap: true,
target: "node16",
minify: false,
},
resolve: {
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'],
alias: {
'src': path.resolve(__dirname, './src'),
// './generated': path.resolve(__dirname, './generated'),
}
},
};
});