-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
59 lines (57 loc) · 1.67 KB
/
vite.config.js
File metadata and controls
59 lines (57 loc) · 1.67 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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
export default defineConfig(({ command }) => {
// Dev server mode: serve the example/ demo app
if (command === 'serve') {
return {
plugins: [react()],
// Force a single React instance regardless of where it's imported from
// (prevents "Invalid hook call" when @formio/js pulls in its own React)
resolve: {
dedupe: ['react', 'react-dom'],
},
// Handle JSX in .js and .jsx files
esbuild: {
loader: 'jsx',
include: /\.jsx?$/,
},
// optimizeDeps needed because @formio/js is CJS
optimizeDeps: {
include: ['@formio/js'],
esbuildOptions: {
loader: { '.js': 'jsx' },
},
},
};
}
// Build mode: library output
return {
plugins: [react()],
build: {
lib: {
entry: resolve(__dirname, 'src/index.js'),
name: 'FormEngine',
formats: ['es', 'umd'],
fileName: (format) => `form-engine.${format}.js`,
},
rollupOptions: {
// Externalize react, react-dom, and all @formio/js imports
external: (id) => {
if (id === 'react' || id === 'react-dom' || id.startsWith('react-dom/')) return true;
if (id === '@formio/js' || id.startsWith('@formio/js/')) return true;
if (id === 'eventemitter2') return true;
return false;
},
output: {
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'react-dom/client': 'ReactDOMClient',
'@formio/js': 'Formio',
},
},
},
},
};
});