我一直在寻找如何将handlebars-loader与webpack结合使用的示例,但似乎没有适用于webpack 4的实例。
错误信息
ERROR in ./src/templates/property-list-item.hbs
Module build failed: TypeError: Cannot read property 'handlebarsLoader' of undefined
at getLoaderConfig (/Users/Sam/Desktop/mettamware/Public/js/node_modules/handlebars-loader/index.js:24:37)
at Object.module.exports (/Users/Sam/Desktop/mettamware/Public/js/node_modules/handlebars-loader/index.js:32:15)
@ ./src/property-list.js 5:0-58 40:23-31
@ ./src/app.js
当我查看node_modeules/handlerbars-loader/index.js
时,问题函数如下
function getLoaderConfig(loaderContext) {
var query = loaderUtils.getOptions(loaderContext) || {};
var configKey = query.config || 'handlebarsLoader';
var config = loaderContext.options[configKey] || {};
delete query.config;
return assign({}, config, query);
}
我的webpack.config.js文件
const path = require('path');
module.exports = {
entry: './src/app.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.hbs$/,
use: [{
loader: "handlebars-loader",
options: {
helperDirs: path.resolve(__dirname, "./src/helpers")
}
}]
}
]
},
node: {
fs: 'empty'
}
};
如果有人能帮忙的话,我将非常感激。我已经搜索了数小时的解决方案,并尝试了很多方法,但没有任何进展。