-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
79 lines (71 loc) · 1.75 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
import { builtinModules } from 'node:module'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'
import tsconfigPaths from 'vite-tsconfig-paths'
import packageJson from './package.json'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const getPackageName = () => packageJson.name
function getPackageNameCamelCase() {
try {
return getPackageName().replace(/-./g, char => char[1]!.toUpperCase())
}
catch (err) {
throw new Error('Name property in package.json is missing.')
}
}
export default defineConfig({
base: './',
esbuild: {
define: {
'process.env': 'import.meta.env',
},
drop: [
/* 'console' */
'debugger',
],
keepNames: true,
treeShaking: true,
color: true,
},
build: {
target: 'esnext',
outDir: './dist',
minify: false,
sourcemap: false,
lib: {
entry: path.resolve(__dirname, 'src/cli.ts'),
name: getPackageNameCamelCase(),
formats: ['es'],
fileName: () => 'cli.js',
// formats: ['es', 'cjs'],
// fileName: format => format === 'es' ? 'cli.js' : 'cli.cjs',
},
rollupOptions: {
external: [
/node_modules/,
...builtinModules,
...builtinModules.map(m => `node:${m}`),
],
// output: {
// chunkFileNames: 'chunks/[name]-[hash].mjs',
// assetFileNames: 'assets/[name]-[hash].[ext]',
// hoistTransitiveImports: false,
// preserveModules: true,
// preserveModulesRoot: 'src',
// },
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
plugins: [
tsconfigPaths(),
dts({
outDir: './dist/dts',
}),
],
})