Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add browser field to package.json to fix webpack
This should close #305, see #305 (comment): > Actually, after reading https://webpack.js.org/configuration/resolve/#resolvemainfields more closely, it sounds like adding a `browser` field to `package.json`, that points to `lib/index.js` (same as `main`) should fix things. > > > resolve.mainFields > > [string] > > > > When importing from an npm package, e.g. import * as D3 from 'd3', this option will determine which fields in its package.json are checked. The default values will vary based upon the target specified in your webpack configuration. > > > > When the target property is set to webworker, web, or left unspecified: > > > > webpack.config.js > > > > module.exports = { > > //... > > resolve: { > > mainFields: ['browser', 'module', 'main'] > > } > > }; > > For any other target (including node): > > > > webpack.config.js > > > > module.exports = { > > //... > > resolve: { > > mainFields: ['module', 'main'] > > } > > }; > > For example, consider an arbitrary library called upstream with a package.json that contains the following fields: > > > > { > > "browser": "build/upstream.js", > > "module": "index" > > } > > When we import * as Upstream from 'upstream' this will actually resolve to the file in the browser property. The browser property takes precedence because it's the first item in mainFields. Meanwhile, a Node.js application bundled by webpack will first try to resolve using the file in the module field. > > I'll open a PR for that.
- Loading branch information