shannonmoeller / handlebars-layouts

Handlebars helpers which implement layout blocks similar to Jinja, Nunjucks (Swig), Pug (Jade), and Twig.

Home Page:http://npm.im/handlebars-layouts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error working with Html-webpack-plugin

unnieayilliath opened this issue · comments

I am using handlebars-layouts with webpack and I use Html-webpack-plugin to generate html file. But if i use extends, webpack throws below error:

ERROR in Template execution failed: Error: Missing helper: "extend"

I am using handlebars-loader with webpack and below is my webpack config.

module: {
       rules: [{
           test: /\.tsx?$/,
           use: 'ts-loader',
           exclude: /node_modules/
       },
       {
           test: /\.hbs$/,
           use: [{
               loader:'handlebars-loader',
               options:{
                   partialDirs: path.resolve(__dirname, "./app/partials"),
                   helperDirs: path.resolve(__dirname, "./node_modules/handlebars-layouts"),
               }
           }]
       }]
   },
.
.
.
.

 new HtmlWebpackPlugin({ 
           filename: 'add.form.html', // name of the output file
           chunks: ['add'], // name of the entry point defined above
           template: './app/add/add.form.hbs' // path to the html for the webpart
       }),

I found this response helpful: pcardune/handlebars-loader#110 (comment)

Just a quick follow-up, it doesn't look like this will ever work with handlebars-loader. handlebars-loader does not add partials to the global Handlebars instance, which this library is looking for. If you manually load the partials into the Handlebars instance, you could potentially get this working.

You are correct that handlebars-layouts expects the partials to be registered globally. I'm not familiar with the webpack loader, so I'm not sure if it's possible. Seems like it might be with the runtime option.

https://gist.github.com/impankratov/18e862e9a54d2ce092138e1a7a052c12#file-webpack-config-js

Closing this as it's more of an issue with the webpack loader than this library.

well, I'm trying to get it to work right now but I think there is no hope for me here.
maybe someone in the future will get here or someone can give me good advice.
handlebars-layouts extension not going to work with handlebars-loader. You have to build your own loader and precompile all this buy yourself to make it work.

The reason is why you can't make it work is just because of handlebars-loader doesn't use partials from runtime you pass to the loader. Maybe I'm wrong but I couldn't find any resource about manual registration of partials from handlebars instance for handlebars-loader. When I pass handlebars instance with already registered partials for some reason handlebars-loader can't find them. Don't be me and don't spend slipless nights on it.

Since loading partials is beyond the scope of this package, this seems like an issue to be solved in handlebars-loader. Sorry it's not working for you. Might want to create an issue in their repo.