Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browser only support #13

Closed
teone opened this issue Sep 19, 2022 · 1 comment · Fixed by #18
Closed

browser only support #13

teone opened this issue Sep 19, 2022 · 1 comment · Fixed by #18

Comments

@teone
Copy link

teone commented Sep 19, 2022

Hi @zoubingwu,
first of all thanks for this, it's a great tool and saves a lot of time!

There is one bit of the implementation that could simplify (in my opinion) the usage for a few people.

When using Webpack in a client side app (eg a React app generated with https://create-react-app.dev/), there are issues in importing modules supposed to run in a node environment.

Because of that, this bit causes a bit of issues:

export const startWorker = () => {
  if (typeof window === "undefined") {
    const { setupServer } = require("msw/node");
    const server = setupServer(...handlers);
    server.listen();
  } else {
    const worker = setupWorker(...handlers);
    worker.start();
  }
};

do you think it would make sense to add a flag like --browser to change that piece of code to smaller when set? For example:

export const startWorker = () => {
    const worker = setupWorker(...handlers);
    worker.start();
};
@zoubingwu
Copy link
Owner

sure, I'm also having the same issue, will fix asap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants