dynamic - 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="">
有用。
我必须做的是,我可以在车把文件中使用动态路径?
解决方案
我在 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')}' }}
推荐阅读
- ruby - 解析器过滤器插件不起作用 Td-agent [Fluentd]
- ios - 存储 UICollectionViewCell 状态
- c# - 在标记范围和未标记范围内解析组件
- scala - 在使用 Semigroupal 的某些 monad 中,我们仍然会失去上下文吗?
- ruby - 我应该如何在 Ruby 中继承变量?
- sql-server - 使用 DDNS 和端口转发的 Google Apps 脚本 JDBC(特别是 sqlserver)连接问题
- java - 从 servlet 中的单选按钮值获取 null
- r - R语言中两个矩阵相乘的错误
- php - 如何在变体形式下拉列表中显示产品变体图像?
- python - 如何在标头中传递基本身份验证 base 64 密钥