Setup mock server for production environments
mainIn production, vite-plugin-mock uses mockjs instead of Connect middleware. This means you cannot access headers or use certain restful URL parameter formats.
To use mocks in production, you must create a mockProdServer.ts file and call createProdMockServer with your mock modules.
Important Limitations:
- No Node Modules: You cannot use Node.js modules inside your
mock.tsfiles, otherwise production will fail. - Testing Only: Only use production mocks for specific testing environments. Do not enable them in actual production environments as they may interfere with real Ajax requests (e.g., file uploads/downloads).
// mockProdServer.ts
import { createProdMockServer } from 'vite-plugin-mock/client'
import testModule from '../mock/test'
export function setupProdMockServer() {
createProdMockServer([...testModule])
}