/ vite.config.ts
vite.config.ts
 1  import { defineConfig } from 'vite'
 2  import react from '@vitejs/plugin-react'
 3  import path from 'path'
 4  import { existsSync } from 'fs'
 5  
 6  // Check if local acdc-design exists for development HMR
 7  const localDesignPath = path.resolve(__dirname, '../acdc-design/src')
 8  const localDesignDistPath = path.resolve(__dirname, '../acdc-design/dist')
 9  const useLocalDesign = existsSync(localDesignPath)
10  
11  export default defineConfig(({ command, mode }) => {
12    const useSourceAlias = command === 'serve' && useLocalDesign
13    const isStaging = process.env.STAGING === 'true' || mode === 'staging'
14    const base = isStaging ? '/stages/home/' : '/'
15  
16    return {
17      base,
18      plugins: [react()],
19      resolve: {
20        alias: {
21          '@': path.resolve(__dirname, './src'),
22          // CSS import must point to dist (PostCSS doesn't use source alias)
23          ...(useSourceAlias && {
24            '@acdc/design/css': path.resolve(localDesignDistPath, 'style.css'),
25            '@acdc/design': localDesignPath,
26          }),
27        },
28      },
29      server: useLocalDesign ? {
30        fs: {
31          allow: ['..', '../acdc-design'],
32        },
33      } : undefined,
34      optimizeDeps: {
35        exclude: useSourceAlias ? ['@acdc/design'] : [],
36      },
37      build: {
38        outDir: 'dist',
39        sourcemap: false,
40        rollupOptions: {
41          output: {
42            manualChunks: {
43              react: ['react', 'react-dom'],
44              router: ['react-router-dom'],
45            },
46          },
47        },
48      },
49    }
50  })