Closed wlepinski closed 8 years ago
I noticed that the plugin is trying to require the .html
files using require().
Yep, that's the issue. Handlebars supports require()
ing partials with the extensions .handlebars
and .hbs
. You'll want to rename your partial files, or add your own extension method.
require.extensions['.html'] = function (module, filename) {
module.exports = fs.readFileSync(filename, 'utf8');
};
Like that, right?
Close. This should do it:
var fs = require('fs');
var handlebars = require('handlebars');
require.extensions['.html'] = function (module, filename) {
module.exports = handlebars.compile(fs.readFileSync(filename, 'utf8'));
};
It's not an issue for gulp.src
as that reads the file as text.
Cool. Closing the issue. Thanks.
I stumbled upon the same issue (want to use partials with .html extension), but I am using the new ES6 module import syntax instead of require:
import hb from 'gulp-hb';
Is there a solution working with this syntax as well?
@derwaldgeist The module syntax currently de-sugars to a require()
call, so the extensions hook still works (as of Node 6).
When native import
lands in Node (likely to be v7), I'll make sure this plugin is compatible.
Thanks!
I'm trying to compile a HTML (Handlebars) file to pure HTML and I'm getting this error:
What am I doing wrong here?