├── .gitignore ├── src └── modules │ ├── c │ ├── test.hbs │ └── index.js │ ├── a │ └── index.js │ ├── b │ └── index.js │ └── bulk.js ├── tasks ├── default.js └── scripts │ └── bulkify.js ├── gulpfile.js ├── readme.md ├── dist ├── index.html └── js │ └── main.js ├── package.json └── .jshintrc /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | node_modules -------------------------------------------------------------------------------- /src/modules/c/test.hbs: -------------------------------------------------------------------------------- 1 | {{#names}} 2 |
  • {{FirstName}} {{LastName}}
  • 3 | {{/names}} -------------------------------------------------------------------------------- /src/modules/a/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function() { 4 | console.log('a'); 5 | }; -------------------------------------------------------------------------------- /src/modules/b/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function () { 4 | console.log('b'); 5 | }; -------------------------------------------------------------------------------- /tasks/default.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var gulp = require('gulp'); 4 | gulp.task('default', ['bulkify'], function () { 5 | gulp.watch(['src/**/*.js', 'src/**/*.hbs'], ['bulkify']); 6 | }); -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var glob = require('glob'); 4 | var filepaths = glob.sync('./tasks/**/*.js'); 5 | 6 | // load gulp tasks from directory 7 | filepaths.forEach(function (filepath) { 8 | require(filepath); 9 | }); -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Bulkify with Gulp 2 | Browserify does not support dynamic require statements. One way to solve this problem is to use Bulkify and Gulp tasks 3 | to transform inline bulk-require calls into statically resolvable require maps. -------------------------------------------------------------------------------- /src/modules/bulk.js: -------------------------------------------------------------------------------- 1 | var bulk = require('bulk-require'); 2 | var components = bulk(__dirname, ['a', 'b', 'c']); 3 | for (var component in components) { 4 | if (components.hasOwnProperty(component)) { 5 | components[component](); 6 | } 7 | } -------------------------------------------------------------------------------- /dist/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Using Bulkify with Gulp 5 | 6 | 7 | 8 |

    Using Bulkify with Gulp

    9 | 10 |

    Check the JS console. It should read:

    11 | a
    12 | b
    13 | c
    14 | 15 |

    Names:

    16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/modules/c/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var template = require('./test.hbs'); 4 | 5 | module.exports = function () { 6 | var names = {'names': [ 7 | { 8 | 'FirstName': 'Christian', 9 | 'LastName': 'Lohr' 10 | }, 11 | { 12 | 'FirstName': 'Jenny', 13 | 'LastName': 'Lohr' 14 | }, 15 | { 16 | 'FirstName': 'Logan', 17 | 'LastName': 'Lohr' 18 | } 19 | ]}; 20 | var rendered = template(names); 21 | document.getElementById('names').innerHTML = rendered; 22 | console.log('c'); 23 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bulkify-gulp", 3 | "version": "0.0.1", 4 | "description": "Using Bulkify with Gulp", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "author": "Christian Lohr ", 13 | "license": "MIT", 14 | "devDependencies": { 15 | "browserify": "~5.9.1", 16 | "bulk-require": "~0.2.1", 17 | "bulkify": "~1.0.2", 18 | "glob": "~4.0.5", 19 | "gulp": "~3.8.7", 20 | "gulp-uglify": "~0.3.1", 21 | "handlebars": "~2.0.0-alpha.4", 22 | "hbsfy": "~2.0.0", 23 | "stream-combiner": "^0.2.1", 24 | "vinyl-buffer": "0.0.0", 25 | "vinyl-source-stream": "~0.1.1" 26 | }, 27 | "browserify": { 28 | "transform": ["hbsfy", "bulkify"] 29 | } 30 | } -------------------------------------------------------------------------------- /tasks/scripts/bulkify.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var gulp = require('gulp'); 4 | var browserify = require('browserify'); 5 | var bulkify = require('bulkify'); 6 | var hbsfy = require('hbsfy'); 7 | var source = require('vinyl-source-stream'); 8 | var entry = './src/modules/bulk.js'; 9 | var output_filename = 'main.js'; 10 | var output_path = './dist/js'; 11 | var buffer = require('vinyl-buffer'); 12 | var ugilfy = require('gulp-uglify'); 13 | var Combine = require('stream-combiner'); 14 | 15 | gulp.task('bulkify', function() { 16 | var bundleStream = browserify({ 17 | entries: entry 18 | }); 19 | var combined = new Combine( 20 | bundleStream 21 | .bundle() 22 | .pipe(source(output_filename)) 23 | .pipe(buffer()) 24 | .pipe(ugilfy()) 25 | .pipe(gulp.dest(output_path))); 26 | 27 | combined.on('error', function(err) { 28 | console.error(err.message) 29 | }); 30 | 31 | return combined; 32 | }); -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | // Settings 3 | "passfail" : false, // Stop on first error. 4 | "maxerr" : 100, // Maximum error before stopping. 5 | 6 | 7 | // Predefined globals whom JSHint will ignore. 8 | "browser" : true, // Standard browser globals e.g. `window`, `document`. 9 | 10 | "node" : true, 11 | "rhino" : false, 12 | "couch" : false, 13 | "wsh" : true, // Windows Scripting Host. 14 | 15 | "jquery" : false, 16 | "ender" : true, 17 | "prototypejs" : false, 18 | "mootools" : false, 19 | "dojo" : false, 20 | 21 | "predef" : [ // Custom globals. 22 | //"exampleVar", 23 | //"anotherCoolGlobal", 24 | //"iLoveDouglas" 25 | ], 26 | 27 | 28 | // Development. 29 | "debug" : false, // Allow debugger statements e.g. browser breakpoints. 30 | "devel" : true, // Allow developments statements e.g. `console.log();`. 31 | 32 | 33 | // ECMAScript 5. 34 | "es5" : true, // Allow ECMAScript 5 syntax. 35 | "strict" : false, // Require `use strict` pragma in every file. 36 | "globalstrict" : false, // Allow global "use strict" (also enables 'strict'). 37 | 38 | 39 | // The Good Parts. 40 | "asi" : true, // Tolerate Automatic Semicolon Insertion (no semicolons). 41 | "laxbreak" : true, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons. 42 | "bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.). 43 | "boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments. 44 | "curly" : true, // Require {} for every new block or scope. 45 | "eqeqeq" : true, // Require triple equals i.e. `===`. 46 | "eqnull" : false, // Tolerate use of `== null`. 47 | "evil" : false, // Tolerate use of `eval`. 48 | "expr" : false, // Tolerate `ExpressionStatement` as Programs. 49 | "forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`. 50 | "immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );` 51 | "latedef" : true, // Prohipit variable use before definition. 52 | "loopfunc" : false, // Allow functions to be defined within loops. 53 | "noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`. 54 | "regexp" : true, // Prohibit `.` and `[^...]` in regular expressions. 55 | "regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`. 56 | "scripturl" : true, // Tolerate script-targeted URLs. 57 | "shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`. 58 | "supernew" : false, // Tolerate `new function () { ... };` and `new Object;`. 59 | "undef" : true, // Require all non-global variables be declared before they are used. 60 | 61 | 62 | // Personal styling preferences. 63 | "newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`. 64 | "noempty" : true, // Prohibit use of empty blocks. 65 | "nonew" : false, // Prohibit use of constructors for side-effects. 66 | "nomen" : true, // Prohibit use of initial or trailing underbars in names. 67 | "onevar" : false, // Allow only one `var` statement per function. 68 | "plusplus" : false, // Prohibit use of `++` & `--`. 69 | "sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`. 70 | "trailing" : true, // Prohibit trailing whitespaces. 71 | "white" : false, // Check against strict whitespace and indentation rules. 72 | "indent" : 4 // Specify indentation spacing 73 | } -------------------------------------------------------------------------------- /dist/js/main.js: -------------------------------------------------------------------------------- 1 | !function e(t,r,n){function a(s,o){if(!r[s]){if(!t[s]){var l="function"==typeof require&&require;if(!o&&l)return l(s,!0);if(i)return i(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var p=r[s]={exports:{}};t[s][0].call(p.exports,function(e){var r=t[s][1][e];return a(r?r:e)},p,p.exports,e,t,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s0?(r.ids&&(r.ids=[r.name]),e.helpers.each(t,r)):n(this);if(r.data&&r.ids){var i=g(r.data);i.contextPath=s.appendContextPath(r.data.contextPath,r.name),r={data:i}}return a(t,r)}),e.registerHelper("each",function(e,t){t||(t=e,e=this);var r,n,a=t.fn,i=t.inverse,o=0,l="";if(t.data&&t.ids&&(n=s.appendContextPath(t.data.contextPath,t.ids[0])+"."),f(e)&&(e=e.call(this)),t.data&&(r=g(t.data)),e&&"object"==typeof e)if(c(e))for(var u=e.length;u>o;o++)r&&(r.index=o,r.first=0===o,r.last=o===e.length-1,n&&(r.contextPath=n+o)),l+=a(e[o],{data:r});else for(var p in e)e.hasOwnProperty(p)&&(r&&(r.key=p,r.index=o,r.first=0===o,n&&(r.contextPath=n+p)),l+=a(e[p],{data:r}),o++);return 0===o&&(l=i(this)),l}),e.registerHelper("if",function(e,t){return f(e)&&(e=e.call(this)),!t.hash.includeZero&&!e||s.isEmpty(e)?t.inverse(this):t.fn(this)}),e.registerHelper("unless",function(t,r){return e.helpers["if"].call(this,t,{fn:r.inverse,inverse:r.fn,hash:r.hash})}),e.registerHelper("with",function(e,t){f(e)&&(e=e.call(this));var r=t.fn;if(!s.isEmpty(e)){if(t.data&&t.ids){var n=g(t.data);n.contextPath=s.appendContextPath(t.data.contextPath,t.ids[0]),t={data:n}}return r(e,t)}}),e.registerHelper("log",function(t,r){var n=r.data&&null!=r.data.level?parseInt(r.data.level,10):1;e.log(n,t)}),e.registerHelper("lookup",function(e,t){return e&&e[t]})}function i(e,t){m.log(e,t)}var s=e("./utils"),o=e("./exception")["default"],l="2.0.0-alpha.4";r.VERSION=l;var u=5;r.COMPILER_REVISION=u;var p={1:"<= 1.0.rc.2",2:"== 1.0.0-rc.3",3:"== 1.0.0-rc.4",4:"== 1.x.x",5:">= 2.0.0"};r.REVISION_CHANGES=p;var c=s.isArray,f=s.isFunction,h=s.toString,d="[object Object]";r.HandlebarsEnvironment=n,n.prototype={constructor:n,logger:m,log:i,registerHelper:function(e,t,r){if(h.call(e)===d){if(r||t)throw new o("Arg not supported with multiple helpers");s.extend(this.helpers,e)}else r&&(t.not=r),this.helpers[e]=t},unregisterHelper:function(e){delete this.helpers[e]},registerPartial:function(e,t){h.call(e)===d?s.extend(this.partials,e):this.partials[e]=t},unregisterPartial:function(e){delete this.partials[e]}};var m={methodMap:{0:"debug",1:"info",2:"warn",3:"error"},DEBUG:0,INFO:1,WARN:2,ERROR:3,level:3,log:function(e,t){if(m.level<=e){var r=m.methodMap[e];"undefined"!=typeof console&&console[r]&&console[r].call(console,t)}}};r.logger=m,r.log=i;var g=function(e){var t=s.extend({},e);return t._parent=e,t};r.createFrame=g},{"./exception":4,"./utils":7}],4:[function(e,t,r){"use strict";function n(e,t){var r;t&&t.firstLine&&(r=t.firstLine,e+=" - "+r+":"+t.firstColumn);for(var n=Error.prototype.constructor.call(this,e),i=0;it){var n=h[r],a=h[t];throw new c("Template was precompiled with an older version of Handlebars than the current runtime. Please update your precompiler to a newer version ("+n+") or downgrade your runtime to an older version ("+a+").")}throw new c("Template was precompiled with a newer version of Handlebars than the current runtime. Please update your runtime to a newer version ("+e[1]+").")}}function a(e,t){if(!t)throw new c("No environment passed to template");t.VM.checkRevision(e.compiler);var r=function(e,r,n,a,i,s,o){a&&(n=p.extend({},n,a));var l=t.VM.invokePartial.call(this,e,r,n,i,s,o);if(null!=l)return l;if(t.compile){var u={helpers:i,partials:s,data:o};return s[r]=t.compile(e,{data:void 0!==o},t),s[r](n,u)}throw new c("The partial "+r+" could not be compiled when running in runtime-only mode")},n={escapeExpression:p.escapeExpression,invokePartial:r,fn:function(t){return e[t]},programs:[],program:function(e,t){var r=this.programs[e],n=this.fn(e);return t?r=s(this,e,n,t):r||(r=this.programs[e]=s(this,e,n)),r},programWithDepth:t.VM.programWithDepth,data:function(e,t){for(;e&&t--;)e=e._parent;return e},merge:function(e,t){var r=e||t;return e&&t&&e!==t&&(r=p.extend({},t,e)),r},noop:t.VM.noop,compilerInfo:e.compiler},a=function(t,r){r=r||{};var i=r.data;return a._setup(r),!r.partial&&e.useData&&(i=u(t,i)),e.main.call(n,t,n.helpers,n.partials,i)};return a._setup=function(r){r.partial?(n.helpers=r.helpers,n.partials=r.partials):(n.helpers=n.merge(r.helpers,t.helpers),e.usePartial&&(n.partials=n.merge(r.partials,t.partials)))},a._child=function(e){return n.programWithDepth(e)},a}function i(e,t){var r=Array.prototype.slice.call(arguments,2),n=this,a=n.fn(e),i=function(e,i){return i=i||{},a.apply(n,[e,n.helpers,n.partials,i.data||t].concat(r))};return i.program=e,i.depth=r.length,i}function s(e,t,r,n){var a=function(t,a){return a=a||{},r.call(e,t,e.helpers,e.partials,a.data||n)};return a.program=t,a.depth=0,a}function o(e,t,r,n,a,i){var s={partial:!0,helpers:n,partials:a,data:i};if(void 0===e)throw new c("The partial "+t+" could not be found");return e instanceof Function?e(r,s):void 0}function l(){return""}function u(e,t){return t&&"root"in t||(t=t?d(t):{},t.root=e),t}var p=e("./utils"),c=e("./exception")["default"],f=e("./base").COMPILER_REVISION,h=e("./base").REVISION_CHANGES,d=e("./base").createFrame;r.checkRevision=n,r.template=a,r.programWithDepth=i,r.program=s,r.invokePartial=o,r.noop=l},{"./base":3,"./exception":4,"./utils":7}],6:[function(e,t,r){"use strict";function n(e){this.string=e}n.prototype.toString=function(){return""+this.string},r["default"]=n},{}],7:[function(e,t,r){"use strict";function n(e){return u[e]||"&"}function a(e){for(var t=1;t":">",'"':""","'":"'","`":"`"},p=/[&<>"'`]/g,c=/[&<>"'`]/;r.extend=a;var f=Object.prototype.toString;r.toString=f;var h=function(e){return"function"==typeof e};h(/x/)&&(h=function(e){return"function"==typeof e&&"[object Function]"===f.call(e)});var h;r.isFunction=h;var d=Array.isArray||function(e){return e&&"object"==typeof e?"[object Array]"===f.call(e):!1};r.isArray=d,r.escapeExpression=i,r.isEmpty=s,r.appendContextPath=o},{"./safe-string":6}],8:[function(e,t){t.exports=e("./dist/cjs/handlebars.runtime")},{"./dist/cjs/handlebars.runtime":2}],9:[function(e,t){t.exports=e("handlebars/runtime")["default"]},{"handlebars/runtime":8}],10:[function(e,t){"use strict";t.exports=function(){console.log("a")}},{}],11:[function(e,t){"use strict";t.exports=function(){console.log("b")}},{}],12:[function(e,t){"use strict";var r=e("./test.hbs");t.exports=function(){var e={names:[{FirstName:"Christian",LastName:"Lohr"},{FirstName:"Jenny",LastName:"Lohr"},{FirstName:"Logan",LastName:"Lohr"}]},t=r(e);document.getElementById("names").innerHTML=t,console.log("c")}},{"./test.hbs":13}],13:[function(e,t){var r=e("hbsfy/runtime");t.exports=r.template({1:function(e,t,r,n){var a,i="function",s=this.escapeExpression;return"\n
  • "+s((a=t.FirstName||e&&e.FirstName,typeof a===i?a.call(e,{name:"FirstName",hash:{},data:n}):a))+" "+s((a=t.LastName||e&&e.LastName,typeof a===i?a.call(e,{name:"LastName",hash:{},data:n}):a))+"
  • \n"},compiler:[5,">= 2.0.0"],main:function(e,t,r,n){var a,i,s,o="function",l=t.blockHelperMissing;return i=t.names||e&&e.names,s={name:"names",hash:{},fn:this.program(1,n),inverse:this.noop,data:n},a=typeof i===o?i.call(e,s):i,t.names||(a=l.call(e,a,s)),a||0===a?a:""},useData:!0})},{"hbsfy/runtime":9}]},{},[1]); --------------------------------------------------------------------------------