doowb / handlebars-helpers-browserify-example

Example using handlebars-helpers in a web browser with browserify.
https://doowb.github.io/handlebars-helpers-browserify-example
MIT License
16 stars 5 forks source link

standalone browserify #2

Open doowb opened 7 years ago

doowb commented 7 years ago

Create an example showing how to use browserify directly to create a standalone bundle to use in existing apps.

bs-thomas commented 6 years ago

+1

I want to know if there's a proper way to do this. I'm requiring the whole handlebars-helpers right now, which is 3MB of stuff in my vendor.js file for some reason.

bs-thomas commented 6 years ago

Referencing #1, I now notice that this can be done. However, is there a way to pass in my own instance of Handlebars while loading these helpers separate?

I did this, but seems to not work:

require('handlebars-helpers/lib/array.js')({ handlebars: Handlebars });
require('handlebars-helpers/lib/comparison.js')({ handlebars: Handlebars });
doowb commented 6 years ago

You would do: Handlebars.registerHelper(require('handlebars-helpers/lib/array.js'));

Each helper collection exports an object of helpers that can be registered with Handlebars directly. This is basically how the main export does it.