Open pemrouz opened 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?
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).
@defunctzombie - any more thoughts on this?
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)
I'm on board :+1:
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
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?
Related issue https://github.com/browserify/browserify/issues/1539. Any plans to merge https://github.com/defunctzombie/node-browser-resolve/pull/84 @defunctzombie @sokra?
In addition to paths, it would be nice to resolve module names:
Before npm used to dedupe packages, it was possible to reliably do something like:
Happy to open a PR - I just wanted to check if this is desirable or not first.