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 support - without bundler #175

Open
Toxicable opened this issue Aug 1, 2019 · 1 comment
Open

browser support - without bundler #175

Toxicable opened this issue Aug 1, 2019 · 1 comment

Comments

@Toxicable
Copy link

(Thanks for reporting an issue to micromatch! If you haven't already read the contributor guidelines, Please do that now, then proceed to fill out the details below.)

Please describe the minimum necessary steps to reproduce this issue:

Bundle micromatch with the Angular CLI

What is happening that shouldn't be?

To best support browsers it's a good idea to not directly rely on nodejs.
So we could either directly remove dependencies on nodejs, or provide conditionals

What should be happening instead?

The libs are very close to supporting browser without any bundler intervention as it stands.
These are the few changes needed.

https://github.com/micromatch/picomatch/blob/master/lib/picomatch.js#L155
This could be replaced with an internal version of basename

https://github.com/micromatch/picomatch/blob/master/lib/utils.js#L3
This could be replaced with a browser check + conditional require

let path;
if(!isBrowser()) {
  path = require('path');
}

https://github.com/micromatch/picomatch/blob/master/lib/utils.js#L4
This could be replaced with

const win32 = !isBrowser() && process.platform === 'win32';
@davakos
Copy link

davakos commented Jan 4, 2022

This issue may receive additional interest soon as the the create-react-app project recently updated to version 5.0 which updates WebPack from v4 => v5. WebPack v5 removes default polyfills for NodeJS core modules, so it looks like if you are using picomatch in a browser project you will now need to polyfill path module with path-browserify manually.

It would be nice to have an option for using picomatch natively in browser code without requiring this manual polyfill.

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