我有一个简单的部分
<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/