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) { export function configMockPlugin(isBuild) {
return viteMockServe({ return viteMockServe({
ignore: /^\_/, mockPath: 'mock/modules',
mockPath: 'mock',
localEnabled: !isBuild, localEnabled: !isBuild,
prodEnabled: isBuild, prodEnabled: isBuild,
injectCode: ` injectCode: `
import { setupProdMockServer } from '../mock/_create-prod-server'; import { setupProdMockServer } from '../mock';
setupProdMockServer(); setupProdMockServer();
`, `,
}) })

View File

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

View File

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

View File

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