0

We noticed that all mocked data we added in our Angular app is included in the main.js bundle on production. All requests still fetch real data, though, so this is working fine, and this means we have configured MSW correctly.

Does this happen by default with MSW? If it does, is it possible to add a feature request for configuring whether we would like this to happen? And if not, what should be done to prevent this from happening?

Ideally, no mocked data should be added to the main.js bundle, since 1) mocked data is not used on production and 2) it increases bundle size.

Progman
  • 16,827
  • 6
  • 33
  • 48

1 Answers1

0

It sounds like you have chosen the wrong place to import and start the worker. Make sure that you import it in environment.ts, as MSW recommends:

import { worker } from '../mocks/browser';

worker.start();

export const environment = {
  production: false,
};

See more in the repository with examples.

Artem Zur
  • 358
  • 1
  • 11