-
Notifications
You must be signed in to change notification settings - Fork 5
/
vite.config.mjs
67 lines (65 loc) · 1.83 KB
/
vite.config.mjs
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
import { defineConfig, transformWithEsbuild } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsconfigPaths from 'vite-tsconfig-paths';
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
export default defineConfig({
// depending on your application, base can also be "/"
base: '',
// plugins: [react(), viteTsconfigPaths()],
server: {
// this ensures that the browser opens upon server start
open: true,
// this sets a default port to 3000
port: 3000,
},
plugins: [
{
name: 'treat-js-files-as-jsx',
async transform(code, id) {
if (!id.match(/src\/.*\.js$/)) return null;
// Use the exposed transform from vite, instead of directly
// transforming with esbuild
return transformWithEsbuild(code, id, {
loader: 'jsx',
jsx: 'automatic',
});
},
},
viteTsconfigPaths,
// Note, for local development, comment this out. For prod, uncomment it
nodePolyfills(),
react(),
],
dedupe: ['react-dom', 'styled-components', 'react', '@interchain-ui/react'],
build: {
commonjsOptions: { transformMixedEsModules: true }, // Change
},
optimizeDeps: {
force: true,
esbuildOptions: {
loader: {
'.js': 'jsx',
},
// Node.js global to browser globalThis
define: {
global: 'globalThis',
},
// Enable esbuild polyfill plugins
plugins: [
NodeGlobalsPolyfillPlugin({
buffer: true,
}),
],
},
},
// define: {
// // By default, Vite doesn't include shims for NodeJS/
// // necessary for segment analytics lib to work
// global: {},
// },
// Node.js global to browser globalThis
define: {
global: 'globalThis',
},
});