You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The browser field is an easy and elegant way to provide server/client-only files inside a node module that doesn't know anything about the bundler. So this would be really cool.
Mhmm I guess. If a browser-field is present, it's save to use this as entry point instead of the main-field. It think it should be an ad-hoc standard so module authors are able to publish isomorphic modules without knowing anything about the actual bundler.
@spikebrehm maybe we/you should spread this as best practice for modules that are supposed to have an isomorphic api but different implementations (like superagent)
yeah would do this, if we decide this should be on by default.
This logic has a performance influence, because we need to check the package.json for each resolved module. It's cached but still influence performance...
I agree with @jhnns that there is value in supporting browser as an ad-hoc standard. Browserify does support it (not that this alone is reason for webpack to) and it provides a very clean way for authors to distribute isomorphic modules.
It seems that having it enabled by default would lead to much reduced confusion and pain in the long run, considering there are already a number of modules that support this standard.
It seems this browser field needs the full path to a file instead of allowing for a path to a directory and defaulting to index.js. I'd like to propose adding this functionality to allow usage similar to node and browserify.
Since the answer isn't posted here, it appears browseris a default field now. Documentation here
Reacted by Gajus Kuizinas, Yoshiya Hinosawa, Debjeet Biswas, Nicolas Escalante, Bernie Stern, Linus Unnebäck, Roman Dvornov, Kevin Chen, Lukas Einfalt, Alec Mev and 5 more
Any idea how you would use this to stop a node module trying to load fs?
For libsodium, adding "browser": { "fs": false }, to packages.json seems to work, but this approach doesn't work for webtorrent, so its not clear if the libsodium project did something different than webtorrent.
Activity
dashed commentedon Feb 3, 2014
May conflict with
libraryfield.jhnns commentedon Feb 3, 2014
The
browserfield is an easy and elegant way to provide server/client-only files inside a node module that doesn't know anything about the bundler. So this would be really cool.jhnns commentedon Feb 3, 2014
It's also supported by browserify afaik
sokra commentedon Feb 12, 2014
Should this be on by default?
jhnns commentedon Feb 12, 2014
Mhmm I guess. If a
browser-field is present, it's save to use this as entry point instead of themain-field. It think it should be an ad-hoc standard so module authors are able to publish isomorphic modules without knowing anything about the actual bundler.@spikebrehm maybe we/you should spread this as best practice for modules that are supposed to have an isomorphic api but different implementations (like superagent)
sokra commentedon Feb 12, 2014
Currently you can enable it with:
jhnns commentedon Feb 12, 2014
Maybe it should be derived from the
target-field.sokra commentedon Feb 12, 2014
yeah would do this, if we decide this should be on by default.
This logic has a performance influence, because we need to check the
package.jsonfor each resolved module. It's cached but still influence performance...spikebrehm commentedon Feb 12, 2014
I agree with @jhnns that there is value in supporting
browseras an ad-hoc standard. Browserify does support it (not that this alone is reason for webpack to) and it provides a very clean way for authors to distribute isomorphic modules.It seems that having it enabled by default would lead to much reduced confusion and pain in the long run, considering there are already a number of modules that support this standard.
shawninder commentedon Mar 15, 2016
It seems this
browserfield needs the full path to a file instead of allowing for a path to a directory and defaulting to index.js. I'd like to propose adding this functionality to allow usage similar to node and browserify.mnpenner commentedon May 9, 2017
Since the answer isn't posted here, it appears
browseris a default field now. Documentation heremitra42 commentedon Mar 5, 2018
Any idea how you would use this to stop a node module trying to load fs?
For libsodium, adding "browser": { "fs": false }, to packages.json seems to work, but this approach doesn't work for webtorrent, so its not clear if the libsodium project did something different than webtorrent.
dy commentedon Feb 18, 2019
That does not seem to work with objects defined as
browserfield, eg.Related dy/save-file#14 (comment)
kuceb commentedon Mar 15, 2019
I think this should be re-opened, since webpack does not currently respect objects set in the
browserfield.davnicwil commentedon Mar 24, 2019
@bkucera which version are you on? The following is working for me with v4.19.0