Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
128 lines (118 loc) · 3.72 KB
/
Copy pathvite.config.ts
File metadata and controls
128 lines (118 loc) · 3.72 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
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
import { existsSync, readdirSync, rmSync } from 'node:fs'
import { join, resolve } from 'node:path'
import type { Plugin } from 'vite'
import dts from 'vite-plugin-dts'
import { defineConfig } from 'vitest/config'
const DIST_DIR = resolve(__dirname, 'dist')
const PRESERVED_DIST_ENTRIES = new Set(['mcp-apps'])
function cleanDistPreservingMcpApps(): Plugin {
return {
name: 'clean-dist-preserving-mcp-apps',
apply: 'build',
buildStart() {
if (!existsSync(DIST_DIR)) {
return
}
for (const entry of readdirSync(DIST_DIR)) {
if (PRESERVED_DIST_ENTRIES.has(entry)) {
continue
}
rmSync(join(DIST_DIR, entry), { recursive: true, force: true })
}
},
}
}
export default defineConfig({
plugins: [
cleanDistPreservingMcpApps(),
dts({
include: ['src/**/*'],
exclude: ['src/**/*.test.ts', 'src/**/*.spec.ts', 'src/mcp-apps/**/*'],
entryRoot: 'src',
}),
],
// Build configuration for library mode
build: {
lib: {
// Multiple entry points for CLI and library
entry: {
main: resolve(__dirname, 'src/main.ts'),
'main-http': resolve(__dirname, 'src/main-http.ts'),
index: resolve(__dirname, 'src/index.ts'),
},
formats: ['es'], // ESM only (matches package.json "type": "module")
fileName: (_format, entryName) => `${entryName}.js`,
},
rollupOptions: {
// Externalize dependencies to avoid bundling them
external: [
'@modelcontextprotocol/node',
'@modelcontextprotocol/server',
'@doist/todoist-sdk',
'date-fns',
'dotenv',
'express',
'zod',
// Node.js built-ins (both forms)
'node:path',
'node:fs',
'node:url',
'node:process',
'path',
'fs',
'url',
'process',
/^node:/,
],
output: {
// Generate declarations separately
preserveModules: false,
},
},
target: 'node18', // Target Node.js 18+
outDir: 'dist',
emptyOutDir: false,
sourcemap: false,
ssr: true, // Server-side rendering mode for Node.js
minify: true,
},
// Enable ?raw imports for future HTML/CSS template loading
assetsInclude: ['**/*.html', '**/*.css'],
// Test configuration with Vitest
test: {
globals: true, // Enable global test APIs (describe, it, expect, etc.)
environment: 'node',
include: ['src/**/*.{test,spec}.{js,ts}'],
exclude: ['node_modules', 'dist'],
// Optimize for CI - avoid unnecessary bundling
server: {
deps: {
external: ['rollup'],
},
},
coverage: {
provider: 'v8',
include: ['src/**/*.ts'],
exclude: [
'src/**/*.d.ts',
'src/main.ts', // Exclude the MCP server entry point
'src/**/*.test.ts',
'src/**/*.spec.ts',
],
reporter: ['text', 'json', 'html'],
},
},
// Resolve configuration
resolve: {
alias: {
// Enable clean imports within src/
'@': resolve(__dirname, 'src'),
},
},
// Ensure proper handling of ESM for Node.js
esbuild: {
target: 'node18',
format: 'esm',
platform: 'node',
},
})