shaketbaby / directory-named-webpack-plugin

A Webpack plugin that treats a file with the name of directory as the index file
MIT License
182 stars 17 forks source link

Default value of "honorPackage" should correspond to webpack config's resolve.mainFields #47

Closed leo-buneev closed 4 years ago

leo-buneev commented 4 years ago

Webpack allows to customize "resolve.mainFields" for package.json - https://webpack.js.org/configuration/resolve/#resolvemainfields

Adding this plugin overrides resolve.mainFields with it's honorPackage, which is ['main'] by default.

In my case I was building app for browser, but needed to include node-fetch. In it's package.json it has main pointing to node.js version, and browser pointing to browser version.

Directory-named-webpack-plugin makes webpack prioritize main over browser in this case, which is wrong.

It is easy to fix it with correct honorPackage setting, but think it would be good if honorPackage defaulted to webpack.config.mainFields

shaketbaby commented 4 years ago

Thanks for raising this, the default value of honorPackage was set to maintain backward compatibility so projects started with older version of this plugin continues to work after upgrading the plugin.

leo-buneev commented 4 years ago

Ah, fair enough.

Then you can close this issue (not surer if it's better to close it or leave it open) - if somebody else will have problems, they will stumble upon this issue and see the solution.

For the record, to have default webpack resolution behavior, you need to set honorPackage: ['browser', 'module', 'main']