nikku / karma-browserify

A fast Browserify integration for Karma that handles large projects with ease
MIT License
321 stars 50 forks source link

Does not seem to respect browser field in packge.json #196

Closed alanclarke closed 8 years ago

alanclarke commented 8 years ago

Should karma-browserify respect the browser field in a modules' package.json, as per https://github.com/substack/browserify-handbook#browser-field?

alanclarke commented 8 years ago

or is there another way of achieving the same

nikku commented 8 years ago

May not be the case.

Please provide a bit more context for your case.

alanclarke commented 8 years ago

For example, ideally if we put a browser field in https://github.com/nikku/karma-browserify/blob/master/example/package.json like so:

  "main": "lib/a.js",
  "browser": { "./lib/a.js": "./lib/b.js" }

i would expect any code running in karma that does require('./lib/a.js') to actually be given module b, and for browserify to only bundle module b

This is useful when creating isomorphic modules. In our case we are creating on a cross platform logger, in the browser we want to use some apis available to chrome but that would error in node, (e.g. window.console), whereas in node we might bundle chalk and other things which are not meant for the browser

alanclarke commented 8 years ago

Ah so actually this does work beautifully, but for reference my issue is that when using this feature need to be careful with the order in which things are loaded and to not specify the replaced file in karma config files array