SlexAxton / require-handlebars-plugin

A plugin for handlebars in require.js (both in dev and build)
804 stars 202 forks source link

Handlebars is tightly coupled #253

Open jscharett opened 8 years ago

jscharett commented 8 years ago

Looking at the doc, it states that you can use 'handlebarsPath' to specify the path to a different version of handlebars. However, looking at the hbs plugin, it requires 'hbs/handlebars'. It only seems to use the handlebarsPath when compiling the templates. In order for me to truly use a different version of handlebars, I need to set of a path in my require.config to point to the new version. Would be nice if the plugin could handle this for me in some fashion, so I don't need to specify 2 paths to handlebars in my config.

prantlf commented 7 years ago

Currently all dependencies are required immediately in the main define function of the hbs module. The plugin configuration is not accessible there yet. That's why the config.hbs.handlebarsPath setting, which gets applied during the build later in the module, affects only the compile phase.

Workarounds:

  1. Define alias for "hbs/handlebars" pointing to your own module path by require.config().
  2. Replace "hbs/handlebars" in this module by your own module path.
  3. Rewrite this module, so that it requires dependencies when the load method of the plugin gets called. You will have access to config.hbs.handlebarsPath then.
neetusn commented 3 years ago

completely new to this package and trying to upgrade the existing legacy code with below config,

require.config({ baseUrl: "./js", paths: { hbs: 'libraries/hbs/hbs', ...... }, hbs: { // optional helpers: true, // default: true i18n: false, // default: false templateExtension: 'tmpl', // default: 'hbs' partialsUrl: '', // default: '' },shim: { mxG: { exports: 'mxGraph', deps: ['mxGConfig', 'override'] }, jqueryactual: { exports: 'jqueryactual', deps: ['jquery-external'] }, uniform: { deps: ['jquery-external'] }, datatables: { deps: ['jquery-external'] }, toolbarRenderer: { deps: ['uniform'] }, menuManager: { deps: ['menu', 'menuItem'] }, renderManager: { deps: ['promise', 'canvasToBlob'] }, html2canvas: { exports: 'html2canvas' }, graphRenderer: { deps: ['jqueryactual'] }, canvg: { exports: 'canvg' }, filesaver: { exports: 'saveAs' }, handlebars: { exports: 'Handlebars' } }

and I need to upgrade the current hbs/hbs/handlebars.js -> v1.3.0 to v4.7.6

no luck with this approach, need your help for the same

Thanks in advance