Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { defineConfig } from 'vite'
- import react from '@vitejs/plugin-react'
- import path from 'path'
- import { nodePolyfills } from 'vite-plugin-node-polyfills';
- import commonjs from 'vite-plugin-commonjs';
- // https://vitejs.dev/config/
- export default defineConfig({
- plugins: [
- react(),
- nodePolyfills(),
- commonjs({
- filter(id) {
- // `node_modules` is exclude by default, so we need to include it explicitly
- // https://github.com/vite-plugin/vite-plugin-commonjs/blob/v0.7.0/src/index.ts#L125-L127
- if (id.includes("node_modules/")) {
- return true
- }
- },
- }),
- ],
- resolve: {
- mainFields: ['module', 'browser', 'main'], // Prioritize "module" over "main"
- conditions: ['module', 'import', 'browser', 'default'], // Prioritize ESM conditions
- alias: [
- { find: '@', replacement: path.resolve(__dirname, './src') },
- { find: 'react-intl', replacement: path.resolve(__dirname, 'node_modules/react-intl') },
- { find: '@socket.io/component-emitter', replacement: path.resolve(__dirname, 'node_modules/@socket.io/component-emitter/lib/esm/index.js') },
- { find: /^@socket.io\/component-emitter($|\/)/, replacement: path.resolve(__dirname, 'node_modules/@socket.io/component-emitter/lib/esm/index.js') },
- { find: 'form-data', replacement: path.resolve(__dirname, 'node_modules/form-data/lib/form_data.js') }, // Optional alias
- // Force ESM entry for all @datadog/browser-rum imports
- { find: '@datadog/browser-rum', replacement: path.resolve(__dirname, 'node_modules/@datadog/browser-rum/esm/entries/main.js') },
- { find: /^@datadog\/browser-rum($|\/.*)/, replacement: path.resolve(__dirname, 'node_modules/@datadog/browser-rum/esm/entries/main.js') },
- { find: '@datadog/browser-core', replacement: path.resolve(__dirname, 'node_modules/@datadog/browser-core/esm/index.js') },
- { find: /^@datadog\/browser-core($|\/.*)/, replacement: path.resolve(__dirname, 'node_modules/@datadog/browser-core/esm/index.js') },
- ],
- dedupe: ['react-intl']
- },
- define: {
- 'process.env': {}, // Mock process.env as an empty object
- },
- // Add optimizeDeps if you have issues with specific dependencies
- optimizeDeps: {
- include: ['react-intl', 'pngjs', '@ericblade/quagga2', 'exceljs', 'socket.io-client', 'engine.io-client', "axios", "form-data"],
- exclude: ['@socket.io/component-emitter', '@datadog/browser-rum', '@datadog/browser-core'], // Exclude from pre-bundling
- },
- build: {
- commonjsOptions: {
- include: [/node_modules/, /pngjs/, /@ericblade\/quagga2/, 'exceljs', /form-data/],
- transformMixedEsModules: true,
- esmExternals: true,
- requireReturnsDefault: "auto"
- },
- target: "esnext",
- rollupOptions: {
- onwarn: () => {
- },
- output: {
- interop: 'auto',
- },
- },
- },
- // assetsInclude: ['**/*.json'],
- json: {
- stringify: true,
- namedExports: false,
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement