-
Notifications
You must be signed in to change notification settings - Fork 5k
Expand file tree
/
Copy pathvite.worker.config.ts
More file actions
50 lines (45 loc) · 1.35 KB
/
Copy pathvite.worker.config.ts
File metadata and controls
50 lines (45 loc) · 1.35 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
import { builtinModules, createRequire } from 'node:module'
import path from 'node:path'
import { defineConfig } from 'vite'
const require = createRequire(import.meta.url)
const pkg = require('./package.json') as {
dependencies?: Record<string, string>
optionalDependencies?: Record<string, string>
}
const productionDeps = Object.keys({
...(pkg.dependencies ?? {}),
...(pkg.optionalDependencies ?? {}),
})
const nodeBuiltinSet = new Set(builtinModules)
function matchesPackage(id: string, name: string): boolean {
return id === name || id.startsWith(`${name}/`)
}
function isExternal(id: string): boolean {
if (id === 'electron') return true
if (id.startsWith('node:')) return true
if (nodeBuiltinSet.has(id)) return true
return productionDeps.some((name) => matchesPackage(id, name))
}
export default defineConfig({
build: {
outDir: 'dist/core/plugin/host',
emptyOutDir: true,
target: 'node20',
lib: {
entry: 'src/core/plugin/host/quick-js-worker.ts',
formats: ['cjs'],
fileName: () => 'quick-js-worker.cjs',
},
rollupOptions: {
external: isExternal,
},
},
resolve: {
conditions: ['node', 'default'],
mainFields: ['main', 'module'],
alias: {
'@shared': path.resolve(import.meta.dirname, 'src/shared'),
'@core': path.resolve(import.meta.dirname, 'src/core'),
},
},
})