-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
53 lines (48 loc) · 1.26 KB
/
vite.config.ts
File metadata and controls
53 lines (48 loc) · 1.26 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
import { builtinModules } from 'node:module';
import path from 'node:path';
import { defineConfig } from 'vite';
const NODE_BUILTINS = new Set([
...builtinModules,
...builtinModules.map(moduleName => `node:${moduleName}`),
]);
function preserveCliShebang() {
const shebang = '#!/usr/bin/env node';
return {
name: 'preserve-cli-shebang',
renderChunk(code: string, chunk: { isEntry: boolean; name: string }) {
if (!chunk.isEntry || chunk.name !== 'cli') {
return null;
}
return {
code: `${shebang}\n${code.replace(/^#!.*\n/, '')}`,
map: null,
};
},
};
}
export default defineConfig({
build: {
lib: {
entry: {
cli: path.resolve(__dirname, 'src/cli.ts'),
main: path.resolve(__dirname, 'src/main.ts'),
},
formats: ['cjs'],
fileName: (_format, entryName) => `${entryName}.js`,
},
minify: 'esbuild',
outDir: 'dist',
reportCompressedSize: false,
sourcemap: false,
target: 'node20',
rollupOptions: {
external: source => NODE_BUILTINS.has(source),
output: {
chunkFileNames: 'chunks/[name]-[hash].js',
entryFileNames: '[name].js',
exports: 'named',
},
plugins: [preserveCliShebang()],
},
},
});