@@ -32,6 +32,10 @@ module.exports = function (grunt) {
32
32
singleRun : false
33
33
}
34
34
} ,
35
+ exec : {
36
+ // work around https://github.com/substack/node-browserify/pull/1151
37
+ bundle : './node_modules/.bin/browserify --standalone <%= pkg.name %> --external url --external css-font-face-src --external cssom src/inline.js | ./node_modules/.bin/derequire > build/<%= pkg.name %>.bundled.js'
38
+ } ,
35
39
browserify : {
36
40
xmlserializer : {
37
41
src : [ ] ,
@@ -81,16 +85,6 @@ module.exports = function (grunt) {
81
85
debug : true
82
86
}
83
87
}
84
- } ,
85
- browser : {
86
- src : 'src/inline.js' ,
87
- dest : 'build/<%= pkg.name %>.js' ,
88
- options : {
89
- browserifyOptions : {
90
- standalone : '<%= pkg.name %>' ,
91
- } ,
92
- external : [ 'cssom' , 'url' , 'css-font-face-src' ]
93
- }
94
88
}
95
89
} ,
96
90
clean : {
@@ -100,6 +94,7 @@ module.exports = function (grunt) {
100
94
concat : {
101
95
dist : {
102
96
options : {
97
+ // Work around https://github.com/substack/node-browserify/issues/670
103
98
banner : '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
104
99
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
105
100
'* <%= pkg.homepage %>\n' +
@@ -111,22 +106,25 @@ module.exports = function (grunt) {
111
106
" define(['url', 'css-font-face-src', 'cssom'], function (a0,b1,c2) {" ,
112
107
" return (root['<%= pkg.name %>'] = factory(a0,b1,c2));" ,
113
108
" });" ,
114
- " } else if (typeof require === 'object') {" ,
109
+ " } else if (typeof exports === 'object') { // browserify context " ,
115
110
" var cssom;" ,
116
111
" try { cssom = require('cssom'); } catch (e) {}" ,
117
- " module.exports = factory(require('url'), require('css-font-face-src'), cssom);" ,
112
+ " var f = factory(require('url'), require('css-font-face-src'), cssom);" ,
113
+ " for(var prop in f) exports[prop] = f[prop];" ,
118
114
" } else {" ,
119
115
" root['<%= pkg.name %>'] = factory(url,cssFontFaceSrc,window.cssom);" ,
120
116
" }" ,
121
117
"}(this, function (url, cssFontFaceSrc, cssom) {" ,
122
118
" var modules = {url: url, 'css-font-face-src': cssFontFaceSrc, cssom: cssom};" ,
123
119
" var require = function (name) { if (modules[name]) { return modules[name]; } else { throw new Error('Module not found: ' + name); }; };" ,
124
120
" // cheat browserify module to leave the function reference for us" ,
125
- " var module = {}, exports={};\n" ] . join ( '\n' ) ,
126
- footer : [ " return module.exports;" ,
121
+ " var module = {}, exports={};" ,
122
+ " // from here on it's browserify all the way\n" ] . join ( '\n' ) ,
123
+ footer : [ "\n // back to us" ,
124
+ " return module.exports;" ,
127
125
"}));\n" ] . join ( '\n' )
128
126
} ,
129
- src : [ 'build/<%= pkg.name %>.js' ] ,
127
+ src : [ 'build/<%= pkg.name %>.bundled. js' ] ,
130
128
dest : 'dist/<%= pkg.name %>.js'
131
129
}
132
130
} ,
@@ -232,6 +230,7 @@ module.exports = function (grunt) {
232
230
grunt . loadNpmTasks ( 'grunt-browserify' ) ;
233
231
grunt . loadNpmTasks ( 'grunt-umd' ) ;
234
232
grunt . loadNpmTasks ( 'grunt-karma' ) ;
233
+ grunt . loadNpmTasks ( 'grunt-exec' ) ;
235
234
236
235
grunt . registerTask ( 'testDeps' , [
237
236
'browserify:xmlserializer' ,
@@ -258,7 +257,7 @@ module.exports = function (grunt) {
258
257
] ) ;
259
258
260
259
grunt . registerTask ( 'build' , [
261
- 'browserify:browser ' ,
260
+ 'exec:bundle ' ,
262
261
'concat:dist'
263
262
] ) ;
264
263
0 commit comments