webpack handlbars-loader: inlineRequires doesn't work with dynamic path

1k views Asked by At

I have a simple partial

<span class="icon-dim_{{name}}">
  <svg class="icon">
    <use xlink:href="#{{name}}"></use>
  </svg>
  <noscript>
    <img src="../../assets/{{name}}.png" alt="">
  </noscript>
</span>

But i get this error message.

ERROR in ./hbs/partials/icon.hbs    
Module parse failed: Unterminated string constant (10:110)
You may need an appropriate loader to handle this file type.

If I put a static path inside my partial

<img src="../../assets/myIcon.png" alt="">

it works.

What I have todo, that I can use dynamic paths inside a handlebars file?

1

There are 1 answers

1
Gregor Voinov On

I got help at github

https://github.com/pcardune/handlebars-loader/issues/132

use chainged loaders

  {
    test: /\.hbs$/,
    use: [
      {
        loader: 'handlebars-loader'
      },
      {
        loader: 'extract-loader'
      },
      {
        loader: 'html-loader',
        options: {
          interpolate: true
        }
      }
    ]
  }

and then require the asset as a parameter

{{> ./partials/partial asset='${require('./assets/1.jpg')}' }}