Skip to content

Support "browser" field #151

Closed
Closed

Activity

  1. dashed commented on Feb 3, 2014

    @dashed
    Contributor

    May conflict with library field.

  2. jhnns commented on Feb 3, 2014

    @jhnns
    Contributor

    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.

  3. jhnns commented on Feb 3, 2014

    @jhnns
    Contributor

    It's also supported by browserify afaik

  4. sokra commented on Feb 12, 2014

    @sokra
    MemberAuthor

    Should this be on by default?

  5. jhnns commented on Feb 12, 2014

    @jhnns
    Contributor

    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)

  6. reopened this on Feb 12, 2014
  7. sokra commented on Feb 12, 2014

    @sokra
    MemberAuthor

    Currently you can enable it with:

    {
      resolve: {
        packageAlias: "browser"
      }
    }
  8. jhnns commented on Feb 12, 2014

    @jhnns
    Contributor

    Maybe it should be derived from the target-field.

  9. sokra commented on Feb 12, 2014

    @sokra
    MemberAuthor

    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...

  10. spikebrehm commented on Feb 12, 2014

    @spikebrehm

    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.

  11. shawninder commented on Mar 15, 2016

    @shawninder

    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.

  12. mnpenner commented on May 9, 2017

    @mnpenner
    Contributor

    Since the answer isn't posted here, it appears browser is a default field now. Documentation here

  13. mitra42 commented on Mar 5, 2018

    @mitra42

    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.

  14. dy commented on Feb 18, 2019

    @dy

    That does not seem to work with objects defined as browser field, eg.

    "browser": { "index.js": "browser.js", "sync.js": "browser.sync.js" }

    Related dy/save-file#14 (comment)

  15. kuceb commented on Mar 15, 2019

    @kuceb
    Contributor

    I think this should be re-opened, since webpack does not currently respect objects set in the browser field.

  16. davnicwil commented on Mar 24, 2019

    @davnicwil

    @bkucera which version are you on? The following is working for me with v4.19.0

    "browser": {
      "module-name": false
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions