diff --git a/build/plugin/mock.js b/build/plugin/mock.js index 6c2d583..d598b2c 100644 --- a/build/plugin/mock.js +++ b/build/plugin/mock.js @@ -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(); `, }) diff --git a/mock/_create-prod-server.js b/mock/index.js similarity index 74% rename from mock/_create-prod-server.js rename to mock/index.js index 4e0522a..13e5de9 100644 --- a/mock/_create-prod-server.js +++ b/mock/index.js @@ -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) }) diff --git a/mock/auth/index.js b/mock/modules/auth.js similarity index 94% rename from mock/auth/index.js rename to mock/modules/auth.js index c8fa18e..fac75b4 100644 --- a/mock/auth/index.js +++ b/mock/modules/auth.js @@ -1,4 +1,4 @@ -import { resolveToken } from '../_utils' +import { resolveToken } from '../utils' const token = { admin: 'admin', diff --git a/mock/post/index.js b/mock/modules/post.js similarity index 100% rename from mock/post/index.js rename to mock/modules/post.js diff --git a/mock/user/index.js b/mock/modules/user.js similarity index 94% rename from mock/user/index.js rename to mock/modules/user.js index b637880..178380d 100644 --- a/mock/user/index.js +++ b/mock/modules/user.js @@ -1,4 +1,4 @@ -import { resolveToken } from '../_utils' +import { resolveToken } from '../utils' const users = { admin: { diff --git a/mock/_utils.js b/mock/utils.js similarity index 100% rename from mock/_utils.js rename to mock/utils.js