require-handlebars-plugin icon indicating copy to clipboard operation
require-handlebars-plugin copied to clipboard

excludeHbsParser does not seem to have any effect

Open chearon opened this issue 10 years ago • 5 comments

I followed the example.build.js found in the demo directory, but setting all of the pragmas still leaves me with the full Handlebars compiler built into my source.

Grepping 1.0.0 for excludeHbsParser gives no results other than the build config, so I don't think it's actually being used anywhere.

That's the (I think) objective thing I found, now if I may make a couple suggestions:

  1. The readme could be amended to provide something like the build config to show people how to optimize their build. I suspect most users have the entire Handlebars compiler built into their project
  2. Could we just adopt the same config as the requirejs text plugin, and use stubModules for the optimized plugin? To do that you'd need to (a) not require hbs in compiled templates and (b) get it to load handlebars.runtime.js which the compiled templates need, maybe by having users adjust their paths.config

chearon avatar Oct 21 '15 23:10 chearon

I was able to achieve the right build without having to fork the code:

   stubModules: ['hbs', 'hbs/underscore', 'hbs/json2'],
   onBuildWrite: function (moduleName, path, contents) {
     if (moduleName === 'hbs/handlebars') {
       return grunt.file.read('vendor/require-handlebars-plugin/hbs/handlebars.runtime.js')
         .replace('define(factory);', 'define(\'hbs/handlebars\', factory);');
     } else {
       return contents;
     }
   }

I still think the pragmas could be dropped and the documentation updated, I'm willing to help. Seems like it's been agreed that's the best way to do plugins according to @jrburke here https://github.com/jrburke/r.js/issues/116

chearon avatar Oct 22 '15 20:10 chearon

Happy to take a PR for it.

On Thu, Oct 22, 2015 at 3:13 PM Caleb Hearon [email protected] wrote:

I was able to achieve the right build without having to fork the code:

stubModules: ['hbs', 'hbs/underscore', 'hbs/json2'], onBuildWrite: function (moduleName, path, contents) { if (moduleName === 'hbs/handlebars') { return grunt.file.read('vendor/require-handlebars-plugin/hbs/handlebars.runtime.js') .replace('define(factory);', 'define('hbs/handlebars', factory);'); } else { return contents; } }

I still think the pragmas could be dropped and the documentation updated, I'm willing to help. Seems like it's been agreed that's the best way to do plugins according to @jrburke https://github.com/jrburke here jrburke/r.js#116 https://github.com/jrburke/r.js/issues/116

— Reply to this email directly or view it on GitHub https://github.com/SlexAxton/require-handlebars-plugin/issues/244#issuecomment-150343416 .

SlexAxton avatar Oct 22 '15 21:10 SlexAxton

See what you think of my branch for this issue: https://github.com/chearon/require-handlebars-plugin/tree/issue-244

I didn't have to change hbs.js except to remove the pragmas. So I've just updated config/readme to show the stubModules way of optimizing out the plugin. The demo-build/main.js is now like 4,000 lines shorter because it stubs out the whole module this time

chearon avatar Oct 25 '15 19:10 chearon

Yea. Might need a couple more words in the readme (or a link) on how to get the optimized output, but the code looks great. PR me?

SlexAxton avatar Oct 25 '15 19:10 SlexAxton

cool! Just added some stuff to the readme and opened a PR

chearon avatar Oct 25 '15 20:10 chearon