Skip to content

Package replacement as a browser field

Hello @substack @feross @zertosh @hughsk!

There is a chance I’m missing something, but is there any specific reason why we cannot implement package replacement in browser field, not only the file replacement?

"browser": "package-analog-for-browser",
"browser": {
  "some-node-package": "some-browser-package"
}

instead of

"browser": "./package-shim.js",
"browser": {
  "some-node-package": "./some-node-package-shim.js"
}

Often I see a situation where packages are just being targeted to single platform and have 1:1 analog in other platform, e. g:

In some cases, like the glslify-sync, absence of that feature is really painful, for if we had the opportunity to set package replacement, we could avoid duplicating code and keep consistent API.

There are modules like aliasify, but they are... too opinionated and do not actually solve the cases like above.