refactor: simplify mock setup

This commit is contained in:
张传龙 2022-06-26 18:42:07 +08:00
parent 73c82520ca
commit cb5dd34e17
6 changed files with 5 additions and 9 deletions

View File

@ -2,12 +2,11 @@ import { viteMockServe } from 'vite-plugin-mock'
export function configMockPlugin(isBuild) {
return viteMockServe({
ignore: /^\_/,
mockPath: 'mock',
mockPath: 'mock/modules',
localEnabled: !isBuild,
prodEnabled: isBuild,
injectCode: `
import { setupProdMockServer } from '../mock/_create-prod-server';
import { setupProdMockServer } from '../mock';
setupProdMockServer();
`,
})

View File

@ -1,11 +1,8 @@
import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer'
const modules = import.meta.globEager('./**/*.js')
const modules = import.meta.globEager('./modules/*.js')
const mockModules = []
Object.keys(modules).forEach((key) => {
if (key.includes('/_')) {
return
}
mockModules.push(...modules[key].default)
})

View File

@ -1,4 +1,4 @@
import { resolveToken } from '../_utils'
import { resolveToken } from '../utils'
const token = {
admin: 'admin',

View File

@ -1,4 +1,4 @@
import { resolveToken } from '../_utils'
import { resolveToken } from '../utils'
const users = {
admin: {