Adding support for CommonJS browser environments.
This commit replaces lib/server.js with lib/browser.js when the code is being bundled as CommonJS for browser environments using tools that look at the "browser" option on the package.json file as outlined on https://gist.github.com/shtylman/4339901.
The change allows to require the "dustjs-linkedin" on browser environments without having to make use of the "vm" module as it currently occurs when the lib/server.js is being bundled.
I've tested this change by running:
browserify --standalone dust . > ./dist/browserified-dust.js
and updating the test/test.html scripts to include the browserified version instead of lib/[dust,parser,compiler].js.
A sample browserified version can be found on https://gist.github.com/bermi/03ee5117c0dfca74322b. It happens to be just 7KB larger than the combined version.
I was also having the same problem trying to use dust with browserify and on my copy made the following change:
if (typeof exports !== "undefined") {
- if (typeof process !== "undefined") {
- require('./server')(dust);
- }
module.exports = dust;
}
Obviously being able to use dustjs-linkedin directly from NPM without hacks would be much nicer :)