Skip to content

Commit

Permalink
Make client compatible with AMD loaders. Issue socketio#338.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfilatov authored and ronquilent committed Nov 23, 2012
1 parent 41c2ba3 commit 7cece88
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions bin/builder.js
Expand Up @@ -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(\"socket.io\", [], function () { return io; });" +
"\n}\n})();";


/**
* Builds a custom Socket.IO distribution based on the transports that you
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 7cece88

Please sign in to comment.