Browse files

Merge pull request #453 from sfilatov/master

Make client compatible with AMD loaders. Issue #338
  • Loading branch information...
2 parents 41c2ba3 + f5d55ba commit 4e78ece7b7710e9f45c8e8d3c40699e3c7ce2157 @rauchg rauchg committed Sep 8, 2012
Showing with 9 additions and 3 deletions.
  1. +9 −3 bin/builder.js
View
12 bin/builder.js
@@ -85,12 +85,16 @@ var baseTransports = {
/**
* Wrappers for client-side usage.
- * This enables usage in both top-level browser window and client-side CommonJS systems.
+ * This enables usage in top-level browser window, client-side CommonJS systems and AMD loaders.
* If doing a node build for server-side client, this wrapper is NOT included.
* @api private
*/
var wrapperPre = "\nvar io = ('undefined' === typeof module ? {} : module.exports);\n(function() {\n";
-var wrapperPost = "\n})();";
+
+var wrapperPost = "\nif (typeof define === \"function\" && define.amd) {" +
+ "\n define([], function () { return io; });" +
+ "\n}\n})();";
+
/**
* Builds a custom Socket.IO distribution based on the transports that you
@@ -197,7 +201,9 @@ var builder = module.exports = function () {
}
// post-wrapper for non-server-side builds
- if (!settings.node)code += wrapperPost;
+ if (!settings.node) {
+ code += wrapperPost;
+ }
code = activeXObfuscator(code);

0 comments on commit 4e78ece

Please sign in to comment.