From efca3c8ef5665fe3cf2802f866db0c73755824e0 Mon Sep 17 00:00:00 2001 From: Spike Brehm Date: Mon, 27 May 2013 11:22:25 -0700 Subject: [PATCH] Support AMD and CommonJS out of the box --- dist/handlebars.js | 19 +++++++++++++++---- dist/handlebars.runtime.js | 19 +++++++++++++++---- lib/handlebars/browser-prefix.js | 5 ++--- lib/handlebars/browser-suffix.js | 14 +++++++++++++- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/dist/handlebars.js b/dist/handlebars.js index b0ab5ae2..07d39631 100644 --- a/dist/handlebars.js +++ b/dist/handlebars.js @@ -23,9 +23,8 @@ THE SOFTWARE. */ // lib/handlebars/browser-prefix.js -var Handlebars = {}; - -(function(Handlebars, undefined) { +(function(undefined) { + var Handlebars = {}; ; // lib/handlebars/base.js @@ -2235,5 +2234,17 @@ Handlebars.VM = { Handlebars.template = Handlebars.VM.template; ; // lib/handlebars/browser-suffix.js -})(Handlebars); + if (typeof module === 'object' && module.exports) { + // CommonJS + module.exports = Handlebars; + + } else if (typeof define === "function" && define.amd) { + // AMD modules + define(function() { return Handlebars; }); + + } else { + // other, i.e. browser + this.Handlebars = Handlebars; + } +}).call(this); ; diff --git a/dist/handlebars.runtime.js b/dist/handlebars.runtime.js index 8744aa77..04ecac3f 100644 --- a/dist/handlebars.runtime.js +++ b/dist/handlebars.runtime.js @@ -23,9 +23,8 @@ THE SOFTWARE. */ // lib/handlebars/browser-prefix.js -var Handlebars = {}; - -(function(Handlebars, undefined) { +(function(undefined) { + var Handlebars = {}; ; // lib/handlebars/base.js @@ -341,5 +340,17 @@ Handlebars.VM = { Handlebars.template = Handlebars.VM.template; ; // lib/handlebars/browser-suffix.js -})(Handlebars); + if (typeof module === 'object' && module.exports) { + // CommonJS + module.exports = Handlebars; + + } else if (typeof define === "function" && define.amd) { + // AMD modules + define(function() { return Handlebars; }); + + } else { + // other, i.e. browser + this.Handlebars = Handlebars; + } +}).call(this); ; diff --git a/lib/handlebars/browser-prefix.js b/lib/handlebars/browser-prefix.js index 138467d6..a8f17223 100644 --- a/lib/handlebars/browser-prefix.js +++ b/lib/handlebars/browser-prefix.js @@ -1,3 +1,2 @@ -var Handlebars = {}; - -(function(Handlebars, undefined) { +(function(undefined) { + var Handlebars = {}; diff --git a/lib/handlebars/browser-suffix.js b/lib/handlebars/browser-suffix.js index 36c52c09..d357c720 100644 --- a/lib/handlebars/browser-suffix.js +++ b/lib/handlebars/browser-suffix.js @@ -1 +1,13 @@ -})(Handlebars); + if (typeof module === 'object' && module.exports) { + // CommonJS + module.exports = Handlebars; + + } else if (typeof define === "function" && define.amd) { + // AMD modules + define(function() { return Handlebars; }); + + } else { + // other, i.e. browser + this.Handlebars = Handlebars; + } +}).call(this);