Node browser resolution strategy
See original GitHub issueI’d like to propose a new resolution strategy that builds upon node
resolution to support https://github.com/defunctzombie/package-browser-field-spec - node+browser
. The core differences is that it reads package.json/browser
to select the entry point or module “aliases”. For example, browser
can point to a string that is used in place of main
when resolving or specific a map of keys to values - where the key is a relative path or a module name and the value is a boolean, relative path or module name.
This module resolution is used in Browserify by default, and can be enabled in Webpack using https://webpack.github.io/docs/configuration.html#resolve-packagealias. It’s the primary way to develop and distribute universal packages that work on node and in browsers.
Edit: It would also be amazing to have the compiler handle this when developing packages so that the aliases are type-checked to be compatible in both environments. For example, it could catch https://github.com/blakeembrey/popsicle/pull/47.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:15
- Comments:10 (4 by maintainers)
Top GitHub Comments
This is also a problem for Angular’s use of Ahead of Time compiler which uses TypeScript’s extensibility feature. When splitting code per platform there must be two paths created
angular2-universal/browser angular2-universal/node
https://github.com/angular/universal-starter/blob/master/src/app/app.browser.module.ts#L3
👍 for this.