Commit 45c8546
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.1 parent 760ab95 commit 45c8546
1 file changed
+1
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
0 commit comments