vite-plugin-config.ts 1.6 KB

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