Home

MSW Hot loading

The index file:

export const init = () => { if (process.env.NODE_ENV === "development") { if (typeof window === "undefined") { const { server } = require("mocks/server") server.listen() if (module.hot) { module.hot.accept("pages/_app.tsx", () => { server.resetHandlers() }) } } else { const { worker } = require("mocks/browser") worker.start() if (module.hot) { module.hot.accept("pages/_app.tsx", () => { worker.resetHandlers() }) } } } }

Repository

https://github.com/okeeffed/developer-notes-nextjs/content/mock-service-worker/msw-hotloading

Sections


Related