Webpack handlebars loader - is there a way to inject context/parameters?

351 views Asked by At

I'm currently trying to setup webpack-dev-middleware (the middleware used in webpack-dev-server, but hosted in my own node application).

One of the requirements I have is to be able to parse my application "index.hbs" through handlebars & then inject everything that normally html-webpack-plugin injects. (a couple scripts with built bundle)

I already found an option to use the handlebars-loader and prepared the configuration for it (according to this)

{
    test: /\.hbs$/,
    loader: "handlebars-loader"
}

This almost works.. The 'almost' part is that normally I used to render my index.hbs like this (the snippet is from node+express app):

app.get(`${ACCESS_PATH}/index`, (req, res) => {
  res.render('index', {
    query: req.query
  });
});

That means that I was actually parsing the template based on query parameters. After lengthy explanation the question is:

Is there any way I can pass "context"/parameters using webpack handlebars-loader to achieve the same behavior now using webpack for serving my file?

Please note that that is development only setup.

0

There are 0 answers