Closed LeoSunQi closed 8 months ago
1.根据文档使用的方式配置 2.在配置 createProdMockServer 代码如下: import { createProdMockServer } from 'vite-plugin-mock/client' let mockModules: any[] = [] const modules = import.meta.glob('./modules/*/.ts', { import: 'default', eager: true, }) Object.keys(modules).forEach((key) => { if (key.includes('./index.ts')) { return } mockModules = mockModules.concat(modules[key]) })
export const setupMock = () => { createProdMockServer(mockModules) }
3.启动vite项目报错:ReferenceError: require is not defined at cleanRequireCache
在vite 4 版本下可以正常运行,升级到vite 5 遇到了同样的错误提示信息。
+1
两种解决方案 https://github.com/vbenjs/vite-plugin-mock/issues/120
1.根据文档使用的方式配置 2.在配置 createProdMockServer 代码如下: import { createProdMockServer } from 'vite-plugin-mock/client' let mockModules: any[] = [] const modules = import.meta.glob('./modules/*/.ts', { import: 'default', eager: true, }) Object.keys(modules).forEach((key) => { if (key.includes('./index.ts')) { return } mockModules = mockModules.concat(modules[key]) })
export const setupMock = () => { createProdMockServer(mockModules) }
3.启动vite项目报错:ReferenceError: require is not defined at cleanRequireCache