Skip to content

Commit

Permalink
perf: auto import mock file
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Jan 17, 2021
1 parent 7279c0a commit df6b5e9
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions mock/_createProductionServer.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer';
import userMock from './sys/user';
import menuMock from './sys/menu';
import tableDemoMock from './demo/table-demo';
import accountDemoMock from './demo/account';
import selectDemoMock from './demo/select-demo';

const modules = import.meta.globEager('./**/*.ts');

const mockModules: any[] = [];
Object.keys(modules).forEach((key) => {
if (key.includes('/_')) {
return;
}
mockModules.push(...modules[key].default);
});

/**
* Used in a production environment. Need to manually import all modules
*/
export function setupProdMockServer() {
createProdMockServer([
...userMock,
...menuMock,
...tableDemoMock,
...accountDemoMock,
...selectDemoMock,
]);
createProdMockServer(mockModules);
}

1 comment on commit df6b5e9

@cynic100
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同步

Please sign in to comment.