vben-admin-thin-next/build/vite/plugin/mock.ts

27 lines
685 B
TypeScript
Raw Normal View History

2021-01-09 23:28:52 +08:00
import { viteMockServe } from 'vite-plugin-mock';
import { ViteEnv } from '../../utils';
2021-01-09 23:28:52 +08:00
export function configMockPlugin(env: ViteEnv, isBuild: boolean) {
const { VITE_USE_MOCK } = env;
const useLocalMock = !isBuild && VITE_USE_MOCK;
const useProdMock = isBuild && VITE_USE_MOCK;
if (useLocalMock || useProdMock) {
2021-01-09 23:28:52 +08:00
const mockPlugin = viteMockServe({
ignore: /^\_/,
mockPath: 'mock',
showTime: true,
localEnabled: useLocalMock,
prodEnabled: useProdMock,
injectCode: `
import { setupProdMockServer } from '../mock/_createProductionServer';
setupProdMockServer();
`,
});
2021-01-09 23:28:52 +08:00
return mockPlugin;
}
2021-01-09 23:28:52 +08:00
return [];
}