vite-plugin-config.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import path from 'path';
  2. import { Plugin, UserConfig } from 'vite';
  3. export function viteConfigPlugin({ packageRoot }: { packageRoot: string }): Plugin {
  4. return {
  5. name: 'vendure:vite-config-plugin',
  6. config: (config: UserConfig) => {
  7. config.root = packageRoot;
  8. config.resolve = {
  9. alias: {
  10. '@': path.resolve(packageRoot, './src/lib'),
  11. },
  12. };
  13. // This is required to prevent Vite from pre-bundling the
  14. // dashboard source when it resides in node_modules.
  15. config.optimizeDeps = {
  16. ...config.optimizeDeps,
  17. exclude: [
  18. ...(config.optimizeDeps?.exclude || []),
  19. '@vendure/dashboard',
  20. '@/providers',
  21. '@/framework',
  22. '@/lib',
  23. '@/components',
  24. '@/hooks',
  25. 'virtual:vendure-ui-config',
  26. 'virtual:admin-api-schema',
  27. 'virtual:dashboard-extensions',
  28. ],
  29. // We however do want to pre-bundle recharts, as it depends
  30. // on lodash which is a CJS packages and _does_ require
  31. // pre-bundling.
  32. include: [
  33. ...(config.optimizeDeps?.include || []),
  34. '@/components > recharts',
  35. '@/components > react-dropzone',
  36. ],
  37. };
  38. return config;
  39. },
  40. };
  41. }