首页 > webpack编译handlebars的问题

webpack编译handlebars的问题

这是我的js文件

Handlebars.registerHelper('like', function (items, options) {
    // 这里省略
});

webpack.config.js文件
引入了handlebars-loader

{
    test: /\.handlebars$/,
    loader: "handlebars-loader" 
}

这样编译会报错,说Handlebars没有定义,该怎么解决呢?原本没定义helper我的handlebars文件可以正常编译


页面要使用handlebar建议直接require handlebar到该页面然后定义为handlebars。这样你才可以自定义handlebars的过滤器helper


配置helperDir即可

handlebar-loader npm官网有如下注解:

利用handlebar-loader不能用register这种方式调用helper,helper需要单独写入js随着loader编译。官方有例子:https://github.com/pcardune/h...
我自己的配置如下图

【热门文章】
【热门文章】