Advertisement
Guest User

Untitled

a guest
Mar 24th, 2025
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { defineConfig } from 'vite'
  2. import react from '@vitejs/plugin-react'
  3. import path from 'path'
  4. import { nodePolyfills } from 'vite-plugin-node-polyfills';
  5. import commonjs from 'vite-plugin-commonjs';
  6.  
  7. // https://vitejs.dev/config/
  8. export default defineConfig({
  9.   plugins: [
  10.     react(),
  11.     nodePolyfills(),
  12.     commonjs({
  13.       filter(id) {
  14.         // `node_modules` is exclude by default, so we need to include it explicitly
  15.         // https://github.com/vite-plugin/vite-plugin-commonjs/blob/v0.7.0/src/index.ts#L125-L127
  16.         if (id.includes("node_modules/")) {
  17.           return true
  18.         }
  19.       },
  20.     }),
  21.   ],
  22.   resolve: {
  23.     mainFields: ['module', 'browser', 'main'], // Prioritize "module" over "main"
  24.     conditions: ['module', 'import', 'browser', 'default'], // Prioritize ESM conditions
  25.     alias: [
  26.       { find: '@', replacement: path.resolve(__dirname, './src') },
  27.       { find: 'react-intl', replacement: path.resolve(__dirname, 'node_modules/react-intl') },
  28.       { find: '@socket.io/component-emitter', replacement: path.resolve(__dirname, 'node_modules/@socket.io/component-emitter/lib/esm/index.js') },
  29.       { find: /^@socket.io\/component-emitter($|\/)/, replacement: path.resolve(__dirname, 'node_modules/@socket.io/component-emitter/lib/esm/index.js') },
  30.       { find: 'form-data', replacement: path.resolve(__dirname, 'node_modules/form-data/lib/form_data.js') }, // Optional alias
  31.       // Force ESM entry for all @datadog/browser-rum imports
  32.       { find: '@datadog/browser-rum', replacement: path.resolve(__dirname, 'node_modules/@datadog/browser-rum/esm/entries/main.js') },
  33.       { find: /^@datadog\/browser-rum($|\/.*)/, replacement: path.resolve(__dirname, 'node_modules/@datadog/browser-rum/esm/entries/main.js') },
  34.       { find: '@datadog/browser-core', replacement: path.resolve(__dirname, 'node_modules/@datadog/browser-core/esm/index.js') },
  35.       { find: /^@datadog\/browser-core($|\/.*)/, replacement: path.resolve(__dirname, 'node_modules/@datadog/browser-core/esm/index.js') },
  36.     ],
  37.     dedupe: ['react-intl']
  38.   },
  39.   define: {
  40.     'process.env': {}, // Mock process.env as an empty object
  41.   },
  42.   // Add optimizeDeps if you have issues with specific dependencies
  43.   optimizeDeps: {
  44.     include: ['react-intl', 'pngjs', '@ericblade/quagga2', 'exceljs', 'socket.io-client', 'engine.io-client', "axios", "form-data"],
  45.     exclude: ['@socket.io/component-emitter', '@datadog/browser-rum', '@datadog/browser-core'], // Exclude from pre-bundling
  46.   },
  47.   build: {
  48.     commonjsOptions: {
  49.       include: [/node_modules/, /pngjs/, /@ericblade\/quagga2/, 'exceljs', /form-data/],
  50.       transformMixedEsModules: true,
  51.       esmExternals: true,
  52.       requireReturnsDefault: "auto"
  53.     },
  54.     target: "esnext",
  55.     rollupOptions: {
  56.       onwarn: () => {
  57.  
  58.       },
  59.       output: {
  60.         interop: 'auto',
  61.       },
  62.     },
  63.   },
  64.   // assetsInclude: ['**/*.json'],
  65.   json: {
  66.     stringify: true,
  67.     namedExports: false,
  68.   }
  69. })
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement