meet/vite.config.ts
2023-08-03 18:26:29 -03:00

51 lines
1.6 KiB
TypeScript

import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill'
import react from '@vitejs/plugin-react-swc'
import rollupNodePolyFill from 'rollup-plugin-polyfill-node'
import { defineConfig, loadEnv } from 'vite'
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
const envVariables = loadEnv(mode, process.cwd())
return {
plugins: [react()],
// Required because the CatalystClient tries to access it
define: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'process.env': {
// eslint-disable-next-line @typescript-eslint/naming-convention
VITE_REACT_APP_DCL_DEFAULT_ENV: envVariables.VITE_REACT_APP_DCL_DEFAULT_ENV
}
},
...(command === 'build'
? {
base: envVariables.VITE_BASE_URL,
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis'
},
// Enable esbuild polyfill plugins
plugins: [
NodeGlobalsPolyfillPlugin({
buffer: true,
process: true
}),
NodeModulesPolyfillPlugin()
]
}
},
build: {
commonjsOptions: {
transformMixedEsModules: true
},
rollupOptions: {
plugins: [rollupNodePolyFill()]
}
}
}
: undefined)
}
})