Skip to content

Commit

Permalink
fix(projects): add prod mockjs switch [添加生产模式的mockjs的开关]
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed May 16, 2023
1 parent 9b19f96 commit 9f5638f
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 362 deletions.
2 changes: 2 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ VITE_COMPRESS=N
VITE_COMPRESS_TYPE=gzip

VITE_PWA=N

VITE_PROD_MOCK=Y
2 changes: 1 addition & 1 deletion build/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function setupVitePlugins(viteEnv: ImportMetaEnv): (PluginOption | Plugin
vueJsx(),
...unplugin(viteEnv),
unocss(),
mock,
mock(viteEnv),
progress(),
pageRoute()
];
Expand Down
19 changes: 12 additions & 7 deletions build/plugins/mock.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { viteMockServe } from 'vite-plugin-mock';

export default viteMockServe({
mockPath: 'mock',
injectCode: `
import { setupMockServer } from '../mock';
setupMockServer();
`
});
export default (viteEnv: ImportMetaEnv) => {
const prodMock = viteEnv.VITE_PROD_MOCK === 'Y';

return viteMockServe({
mockPath: 'mock',
prodEnabled: prodMock,
injectCode: `
import { setupMockServer } from '../mock';
setupMockServer();
`
});
};
4 changes: 2 additions & 2 deletions mock/api/management.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import betterMock from 'better-mock';
import { mock } from 'mockjs';
import type { MockMethod } from 'vite-plugin-mock';

const apis: MockMethod[] = [
{
url: '/mock/getAllUserList',
method: 'post',
response: (): Service.MockServiceResult<ApiUserManagement.User[]> => {
const data = betterMock.mock({
const data = mock({
'list|1000': [
{
id: '@id',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@
"@unocss/vite": "^0.51.13",
"@vitejs/plugin-vue": "^4.2.3",
"@vitejs/plugin-vue-jsx": "^3.0.1",
"better-mock": "^0.3.6",
"conventional-changelog": "^3.1.25",
"cross-env": "^7.0.3",
"eslint": "^8.40.0",
"eslint-config-soybeanjs": "^0.3.7",
"lint-staged": "13.2.2",
"mockjs": "^1.1.0",
"rollup-plugin-visualizer": "^5.9.0",
"sass": "^1.62.1",
"simple-git-hooks": "^2.8.1",
Expand Down
Loading

1 comment on commit 9f5638f

@vercel
Copy link

@vercel vercel bot commented on 9f5638f May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.