我正在使用这个 handlebars-loader对于 webpack 4。现在我想使用自定义助手,但我只得到这个错误
ERROR in Template execution failed: TypeError: __default(...).call is not a function
ERROR in TypeError: __default(...).call is not a function
这是我的 webpack.config
//handlebars-loader
{
test: /\.(hbs)$/,
loader: "handlebars-loader",
options: {
helperDirs: [path.join(__dirname, './src/hbs/helpers')],
partialDirs: [path.join(__dirname, './src/hbs/partials')]
},
}
这是我的简单 helper
const Handlebars = require('handlebars');
Handlebars.registerHelper('repeat', function(n) {
console.log(n);
});
以及我如何使用它
{{#repeat 10}}
<span> repeat</span>
{{/repeat}}
有人知道我做错了什么吗?
最佳答案
我找到了一个解决方案。我必须将助手导出为模块,然后它才能工作。
//repeat.js
module.exports = function(times, options) {
console.log(times);
};
关于helper - 带有 handlebars-loader 的自定义助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51253893/