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

标签 dynamic webpack path webpack-handlebars-loader

我有一个简单的部分

<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="">

它有效。

我必须做什么,我可以在 Handlebars 文件中使用动态路径?

最佳答案

我在 github 上得到了帮助 😎

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

使用链式加载器

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

然后需要 Assets 作为参数

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

关于dynamic - webpack handlbars-loader : inlineRequires doesn't work with dynamic path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51360039/

相关文章:

Python Glob.glob : a wildcard for the number of directories between the root and the destination

c# - Database.Query 返回类型应该是 IEnumerable<dynamic>

scala - 以编程方式向 Spark session 添加/删除执行程序

webpack - angular-cli:切换到 webpack 后环境文件替换被破坏(使用 `ng eject` )

css - Bootstrap 不使用 Webpack 应用 CSS

javascript - 执行 webpack.config 时出错 - 无法解析 'es6-promise'

path - 默认 PATH 变量设置为 .bash_profile 为空

javax.net.ssl.SSLHandshakeException : sun. security.validator.ValidatorException : PKIX path building failed happens on one machine, 但不是另一个

javascript:实现类似 python 的 __getattribute__ 的东西?

c - C中结构中的动态结构数组