refactor: simplify mock setup
This commit is contained in:
parent
73c82520ca
commit
cb5dd34e17
@ -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();
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
|
@ -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)
|
||||||
})
|
})
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
import { resolveToken } from '../_utils'
|
import { resolveToken } from '../utils'
|
||||||
|
|
||||||
const token = {
|
const token = {
|
||||||
admin: 'admin',
|
admin: 'admin',
|
@ -1,4 +1,4 @@
|
|||||||
import { resolveToken } from '../_utils'
|
import { resolveToken } from '../utils'
|
||||||
|
|
||||||
const users = {
|
const users = {
|
||||||
admin: {
|
admin: {
|
Loading…
Reference in New Issue
Block a user