mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-25 02:58:43 +08:00
25 lines
551 B
TypeScript
25 lines
551 B
TypeScript
import { createMockServer } from 'vite-plugin-mock';
|
|
import type { Plugin } from 'vite';
|
|
import { isDevFn, ViteEnv } from '../../utils';
|
|
|
|
export function setupMockPlugin(
|
|
plugins: Plugin[],
|
|
env: ViteEnv,
|
|
mode: 'development' | 'production'
|
|
) {
|
|
const { VITE_USE_MOCK } = env;
|
|
|
|
const useMock = isDevFn(mode) && VITE_USE_MOCK;
|
|
|
|
if (useMock) {
|
|
const mockPlugin = createMockServer({
|
|
ignore: /^\_/,
|
|
mockPath: 'mock',
|
|
showTime: true,
|
|
localEnabled: useMock,
|
|
});
|
|
plugins.push(mockPlugin);
|
|
}
|
|
return plugins;
|
|
}
|