首页 > 解决方案 > webpack handlbars-loader:inlineRequires 不适用于动态路径

问题描述

我有一个简单的部分

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

但我收到此错误消息。

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.

如果我在我的部分中放置一个静态路径

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

有用。

我必须做的是,我可以在车把文件中使用动态路径?

标签: dynamicwebpackpathwebpack-handlebars-loader

解决方案


我在 github 上得到了帮助

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

使用链式装载机

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

然后要求资产作为参数

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

推荐阅读