browserify / browser-resolve

resolve function which support the browser field in package.json
MIT License
102 stars 70 forks source link

Feature Request: Resolve Modules #83

Open pemrouz opened 8 years ago

pemrouz commented 8 years ago

In addition to paths, it would be nice to resolve module names:

"browser": "foo"

Before npm used to dedupe packages, it was possible to reliably do something like:

"browser": "./node_modules/foo/index.js"

Happy to open a PR - I just wanted to check if this is desirable or not first.

defunctzombie commented 8 years ago

hm, not sure what I think of this. What is the thinking here? You would have the browser specific code of the module in a separate module and want to reference it?

pemrouz commented 8 years ago

I think in general most people would expect this to resolve similar to how require resolves.

The specific use case is that I have a bunch of modules that I want to resolve to the identity function (or other times, noop) in the browser, such that when you require this universal module the server-side modules are skipped over in the browser. This is similar to browser: false, but that's restricted to converting to an empty object, which is not always the desired behaviour (i.e. I don't want to throw lots of "object is not a function" errors, or have to add an empty function to each module (ending with multiple in the bundle), or add lots of if statements to work around only being able to dedupe to an empty object).

pemrouz commented 8 years ago

@defunctzombie - any more thoughts on this?

defunctzombie commented 8 years ago

I think this is a good idea. We first need to add it here (https://github.com/defunctzombie/package-browser-field-spec) to document the desired behavior (and probably start a changelog on that page to notify people of spec updates).

Separately, seeing a PR on this here would help folks in testing the feature.

@substack @sokra @Rich-Harris since you all I believe are involved with the more popular package managers. Do you support the browser field spec (I believe browserify and webpack do but could be mistaken)

sokra commented 8 years ago

I'm on board :+1:

pemrouz commented 7 years ago

Thanks for the direction @defunctzombie 👍

Opened PRs https://github.com/defunctzombie/node-browser-resolve/pull/84 and https://github.com/defunctzombie/package-browser-field-spec/pull/6

pemrouz commented 7 years ago

bumping.. is there anything else required before we can land this?

@sokra, @rich-harris: do you make use of node-browser-resolve too or do we need to patch something else?

dy commented 5 years ago

Related issue https://github.com/browserify/browserify/issues/1539. Any plans to merge https://github.com/defunctzombie/node-browser-resolve/pull/84 @defunctzombie @sokra?