_mockProdServer.ts 596 B

1234567891011121314151617181920
  1. import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer';
  2. // Import your mock .ts files one by one
  3. // If you use vite.mock.config.ts, just import the file directly
  4. // You can use the import.meta.glob function to import all
  5. const modules: Record<string, any> = import.meta.glob('./**/*.ts', {
  6. import: 'default',
  7. eager: true,
  8. });
  9. const mockModules = Object.keys(modules).reduce((pre, key) => {
  10. if (!key.includes('/_')) {
  11. pre.push(...modules[key]);
  12. }
  13. return pre;
  14. }, [] as any[]);
  15. export function setupProdMockServer() {
  16. createProdMockServer(mockModules);
  17. }