-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvite.config.ts
47 lines (46 loc) · 1.28 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
import * as vite from 'vite'
import * as path from 'node:path'
export default vite.defineConfig({
resolve: {
alias: {
'react-nil': path.resolve(__dirname, 'src/index.tsx'),
},
},
build: {
sourcemap: true,
target: 'es2020',
lib: {
formats: ['cjs', 'es'],
entry: 'src/index.tsx',
fileName: '[name]',
},
rollupOptions: {
external: (id: string) => !id.startsWith('.') && !path.isAbsolute(id),
output: {
sourcemapExcludeSources: true,
},
},
},
plugins: [
{
name: 'vite-tsc',
generateBundle(options) {
const ext = options.format === 'cjs' ? 'cts' : 'ts'
this.emitFile({ type: 'asset', fileName: `index.d.${ext}`, source: `export * from '../src/index.tsx'` })
},
},
{
name: 'vite-minify',
renderChunk: {
order: 'post',
async handler(code, { fileName }) {
// Preserve pure annotations, but remove all other comments and whitespace
code = code.replaceAll('/* @__PURE__ */', '__PURE__ || ')
const result = await vite.transformWithEsbuild(code, fileName, { minify: true, target: 'es2020' })
result.code = result.code.replaceAll('__PURE__||', '/*@__PURE__*/')
return result
},
},
},
],
})