Skip to content

Commit

Permalink
Fix distributable to be browserifiable, #12 (browserify/browserify#1151
Browse files Browse the repository at this point in the history
  • Loading branch information
cburgmer committed Nov 5, 2016
1 parent 836096e commit a10f67d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 15 additions & 16 deletions Gruntfile.js
Expand Up @@ -32,6 +32,10 @@ module.exports = function (grunt) {
singleRun: false
}
},
exec: {
// work around https://github.com/substack/node-browserify/pull/1151
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'
},
browserify: {
xmlserializer: {
src: [],
Expand Down Expand Up @@ -81,16 +85,6 @@ module.exports = function (grunt) {
debug: true
}
}
},
browser: {
src: 'src/inline.js',
dest: 'build/<%= pkg.name %>.js',
options: {
browserifyOptions: {
standalone: '<%= pkg.name %>',
},
external: ['cssom', 'url', 'css-font-face-src']
}
}
},
clean: {
Expand All @@ -100,6 +94,7 @@ module.exports = function (grunt) {
concat: {
dist: {
options: {
// Work around https://github.com/substack/node-browserify/issues/670
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'* <%= pkg.homepage %>\n' +
Expand All @@ -111,22 +106,25 @@ module.exports = function (grunt) {
" define(['url', 'css-font-face-src', 'cssom'], function (a0,b1,c2) {",
" return (root['<%= pkg.name %>'] = factory(a0,b1,c2));",
" });",
" } else if (typeof require === 'object') {",
" } else if (typeof exports === 'object') { // browserify context",
" var cssom;",
" try { cssom = require('cssom'); } catch (e) {}",
" module.exports = factory(require('url'), require('css-font-face-src'), cssom);",
" var f = factory(require('url'), require('css-font-face-src'), cssom);",
" for(var prop in f) exports[prop] = f[prop];",
" } else {",
" root['<%= pkg.name %>'] = factory(url,cssFontFaceSrc,window.cssom);",
" }",
"}(this, function (url, cssFontFaceSrc, cssom) {",
" var modules = {url: url, 'css-font-face-src': cssFontFaceSrc, cssom: cssom};",
" var require = function (name) { if (modules[name]) { return modules[name]; } else { throw new Error('Module not found: ' + name); }; };",
" // cheat browserify module to leave the function reference for us",
" var module = {}, exports={};\n"].join('\n'),
footer: [" return module.exports;",
" var module = {}, exports={};",
" // from here on it's browserify all the way\n"].join('\n'),
footer: ["\n // back to us",
" return module.exports;",
"}));\n"].join('\n')
},
src: ['build/<%= pkg.name %>.js'],
src: ['build/<%= pkg.name %>.bundled.js'],
dest: 'dist/<%= pkg.name %>.js'
}
},
Expand Down Expand Up @@ -232,6 +230,7 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-umd');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-exec');

grunt.registerTask('testDeps', [
'browserify:xmlserializer',
Expand All @@ -258,7 +257,7 @@ module.exports = function (grunt) {
]);

grunt.registerTask('build', [
'browserify:browser',
'exec:bundle',
'concat:dist'
]);

Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -33,6 +33,7 @@
},
"devDependencies": {
"babel-polyfill": "^6.16.0",
"derequire": "^2.0.3",
"grunt": "^1.0.1",
"grunt-browserify": "^5.0.0",
"grunt-cli": "^1.2.0",
Expand All @@ -41,6 +42,7 @@
"grunt-contrib-jshint": "^1.0.0",
"grunt-contrib-uglify": "^2.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-exec": "^1.0.1",
"grunt-karma": "^2.0.0",
"grunt-regex-check": "~0.1.5",
"grunt-umd": "^2.3.6",
Expand Down

0 comments on commit a10f67d

Please sign in to comment.