flatiron / plates

Light-weight, logic-less, DSL-free, templates for all javascript environments!
MIT License
831 stars 69 forks source link

[Browserify support] Sets module.exports now, in addition to exports #122

Closed Rob-pw closed 9 years ago

Rob-pw commented 9 years ago

Setting the value of "exports" alone won't expose required properties, an empty object ({}) will be returned. Browserify expects 'module.exports', this fixes the issue.

3rd-Eden commented 9 years ago

This obviously breaks in regular browsers because you don't check if module exists in the first place. In addition to that, as this module already works in node.js and using the exports patterns is quite common. If browserify doesn't work that I would suggest opening a bug report there.

Rob-pw commented 9 years ago

@3rd-Eden

What would cause this to break in browsers? I assume you mean this existence check is not sufficient?

if (module && module.exports) {
  module.exports = Plates;
}

Further, although using the exports 'pattern' is common, using module.exports in addition is recommended, since exports is a shorthand.

This fix is not specifically for browserify, but enables plates to work in libraries such as browserify.

3rd-Eden commented 9 years ago

You patch assumed that module is always defined. If it not defined your code will throw an Reference error stating that module is not defined which happens to be the case in browsers.