Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for CommonJS browser environments. #325

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bermi
Copy link

@bermi bermi commented Aug 14, 2013

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.

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.
@xjamundx
Copy link

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 :)

@sethkinast sethkinast removed this from the CommonJS AMD etc. milestone Mar 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants