Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  193] [ 5]  / answers: 1 / hits: 18493  / 12 Years ago, mon, september 24, 2012, 12:00:00

I've created a node module that is essentially just some useful JS that can also be used client side. I know that require.js can load common.js components, but I don't necessarily want to make a mandate that everyone who uses my module client side also needs require or common.js or something. I also don't want to force them to remove the module.exports = ... at the bottom of the file. How do others solve this problem? Do you just create 2 versions, or 2 compiled versions rather? Does module.exports work everywhere?


More From » node.js

 Answers
3

This is what underscore.js does:



if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = _;
}
exports._ = _;
} else {
root['_'] = _;
}

[#82929] Saturday, September 22, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aileent

Total Points: 556
Total Questions: 107
Total Answers: 101

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;