Permalink
Browse files

add AMD support to --standalone. Closes #139

  • Loading branch information...
1 parent 77d8a3b commit b75d03e3b8313e468807a0d26910181cabff702b @wilmoore wilmoore committed with tj Dec 29, 2012
Showing with 17 additions and 7 deletions.
  1. +17 −7 bin/component-build
View
@@ -91,15 +91,25 @@ builder.build(function(err, obj){
: conf.name;
css.write(obj.css);
+
if (standalone) js.write(';(function(){\n');
js.write(obj.require);
js.write(obj.js);
- if (standalone) js.write(' if ("undefined" == typeof module) {\n');
- if (standalone) js.write(' window.' + name + ' = require("' + conf.name + '");\n');
- if (standalone) js.write(' } else {\n');
- if (standalone) js.write(' module.exports = require("' + conf.name + '");\n');
- if (standalone) js.write(' }\n');
- if (standalone) js.write('})();');
+
+ if (standalone) {
+ var umd = [
+ 'if (typeof exports == "object") {',
+ ' module.exports = require("' + conf.name + '");',
+ '} else if (typeof define == "function" && define.amd) {',
+ ' define(require("' + conf.name + '"));',
+ '} else {',
+ ' window["' + name + '"] = require("' + conf.name + '");',
+ '}'
+ ];
+
+ js.write(umd.join('\n'));
+ js.write('})();');
+ }
if (!program.verbose) return;
var duration = new Date - start;
@@ -109,4 +119,4 @@ builder.build(function(err, obj){
log('css', (obj.css.length / 1024 | 0) + 'kb');
log('duration', duration + 'ms');
console.log();
-});
+});

0 comments on commit b75d03e

Please sign in to comment.