-
Notifications
You must be signed in to change notification settings - Fork 18
/
vite.config.ts
57 lines (55 loc) · 1.65 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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import removeConsole from 'vite-plugin-remove-console'
import { resolve } from 'path'
// https://vitejs.dev/guide/build.html#library-mode
export default defineConfig({
plugins: [
react(),
removeConsole({ includes: ['log', 'warn', 'error', 'info'] }),
],
build: {
copyPublicDir: true,
lib: {
entry: resolve(__dirname, 'lib/main.ts'),
name: 'Collapse',
formats: ['es', 'umd', 'cjs'],
fileName: (format) => {
switch (format) {
case 'es':
return 'react-collapse.mjs'
case 'umd':
return 'react-collapse.umd.js'
case 'cjs':
return 'react-collapse.cjs'
default:
throw new Error('Build file unknown format ' + format)
}
},
},
sourcemap: true,
rollupOptions: {
/*
Make sure to externalize deps that shouldn't be bundled
into your library
*/
external: ['react', 'react/jsx-runtime'],
output: {
/*
Provide global variables to use in the UMD build
for externalized deps
*/
globals: {
react: 'React',
'react-dom': 'ReactDOM',
/*
Made up, probably don't exists as CDN or UMD anywhere. If needed, then a polyfill for ReactJsxRuntime or something is needed.
Please use ES Modules in the browser or build tools when using this Collapse library.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
*/
'react/jsx-runtime': 'ReactJsxRuntime',
},
},
},
},
})