@@ -69,8 +69,12 @@ module.exports = function(grunt) {
6969 findNestedDependencies : true ,
7070 include : [ 'src/app' ] ,
7171 onBuildWrite : function ( name , path , contents ) {
72+ if ( name === 'reqwest' ) {
73+ contents = contents . replace ( '}(\'reqwest\', this, function () {' , '}(\'reqwest\', amdclean, function () {' ) ;
74+ }
7275 return require ( 'amdclean' ) . clean ( {
7376 code : contents ,
77+ 'globalObject' : true ,
7478 escodegen : {
7579 'comment' : true ,
7680 'format' : {
@@ -137,26 +141,17 @@ module.exports = function(grunt) {
137141 } ,
138142 useStrict : true ,
139143 wrap : {
140- start : '/*! p5.js v<%= pkg.version %> <%= grunt.template.today("mmmm dd, yyyy") %> */\n' ,
141- end : ''
142- }
143- }
144- } ,
145- min : {
146- options : {
147- baseUrl : '.' ,
148- findNestedDependencies : true ,
149- include : [ 'src/app' ] ,
150- onBuildWrite : function ( name , path , contents ) {
151- return require ( 'amdclean' ) . clean ( contents ) ;
152- } ,
153- optimize : 'uglify2' ,
154- out : 'lib/p5.min.js' ,
155- paths : '<%= requirejs.unmin.options.paths %>' ,
156- useStrict : true ,
157- wrap : {
158- start : '/*! p5.min.js v<%= pkg.version %> <%= grunt.template.today("mmmm dd, yyyy") %> */\n' ,
159- end : ''
144+ start :
145+ [ '/*! p5.js v<%= pkg.version %> <%= grunt.template.today("mmmm dd, yyyy") %> */' ,
146+ '(function (root, factory) {' ,
147+ ' if (typeof define === \'function\' && define.amd)' ,
148+ ' define(\'p5\', [], function () { return (root.returnExportsGlobal = factory());});' ,
149+ ' else if (typeof exports === \'object\')' ,
150+ ' module.exports = factory();' ,
151+ ' else' ,
152+ ' root[\'p5\'] = factory();' ,
153+ '}(this, function () {\n' ] . join ( '\n' ) ,
154+ end : 'return amdclean[\'src_app\'];\n}));'
160155 }
161156 }
162157 } ,
@@ -174,6 +169,15 @@ module.exports = function(grunt) {
174169 }
175170 }
176171 } ,
172+ uglify : {
173+ options : {
174+ banner : '/*! p5.js v<%= pkg.version %> <%= grunt.template.today("mmmm dd, yyyy") %> */'
175+ } ,
176+ build : {
177+ src : '<%= requirejs.unmin.options.out %>' ,
178+ dest : 'lib/p5.min.js'
179+ }
180+ } ,
177181 yuidoc : {
178182 compile : {
179183 name : '<%= pkg.name %>' ,
@@ -208,8 +212,9 @@ module.exports = function(grunt) {
208212 grunt . loadNpmTasks ( 'grunt-contrib-sass' ) ;
209213 grunt . loadNpmTasks ( 'grunt-release' ) ;
210214 grunt . loadNpmTasks ( 'grunt-update-json' ) ;
215+ grunt . loadNpmTasks ( 'grunt-contrib-uglify' ) ;
211216 grunt . registerTask ( 'test' , [ 'jshint' , 'mocha' ] ) ;
212217 grunt . registerTask ( 'yui' , [ 'yuidoc' ] ) ;
213- grunt . registerTask ( 'default' , [ 'jshint' , 'requirejs' , 'mocha' ] ) ;
218+ grunt . registerTask ( 'default' , [ 'jshint' , 'requirejs' , 'mocha' , 'uglify' ] ) ;
214219
215220} ;
0 commit comments