-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
68 lines (57 loc) · 1.94 KB
/
vite.config.ts
File metadata and controls
68 lines (57 loc) · 1.94 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
import path from 'path'
import { emitManifestPlugin } from '@ds-wizard/plugin-sdk/vite'
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import { pluginMetadata } from './src/metadata'
export default defineConfig(({ mode }) => {
const isProd = mode === 'production'
return {
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
// Ensure the bundle works in a plain browser host (no Node "process")
define: {
'process.env.NODE_ENV': JSON.stringify(isProd ? 'production' : 'development'),
'process.env': JSON.stringify({}),
process: JSON.stringify({ env: {} }),
},
build: {
lib: {
entry: {
plugin: 'src/plugin.ts',
},
formats: ['es'],
fileName: (_, name) => `${name}.js`,
},
// Dev: readable + sourcemaps
// Prod: aggressive minify + hidden sourcemaps
sourcemap: isProd ? 'hidden' : true,
minify: isProd ? 'terser' : 'esbuild',
// Only applies when minify === 'terser'
terserOptions: isProd
? {
compress: {
passes: 2,
drop_console: true,
drop_debugger: true,
},
format: {
comments: false,
},
mangle: true,
}
: undefined,
emptyOutDir: true,
// Single-file bundle (handy for plugin loaders)
rollupOptions: {
output: {
inlineDynamicImports: true,
},
plugins: [emitManifestPlugin(pluginMetadata)],
},
},
}
})