我正在尝试将我的相当大的项目从requirejs转换为webpack,并且在尝试转换要由handlebars-loader
处理的把手模板时遇到了问题。我有以下格式的文件:
define([
'hbs!templates/myTemplate',
], function(myTemplate) {...});
这假定存在dist/templates/myTemplate.hbs
。我的webpack.config.js看起来像这样:
var path = require('path');
module.exports = {
entry: './dist/scripts/index.js',
module: {
loaders: [{
loader: 'handlebars-loader',
test: /\.hbs$/,
}],
},
resolve: {
extensions: ['', '.hbs', '.js', '.json'],
root: [
'node_modules',
'dist,
],
},
resolveLoader: {
alias: { hbs: 'handlebars-loader' },
root: [path.join(__dirname, 'node_modules')],
},
output: { filename: 'bundle.js' },
};
然而,当我这样做并运行webpack --config webpack.config.js
时,我在项目中的每个模板引用上都会出现这种类型的错误
>错误在./~/handlebars-loader!dist/templates/myTemplate.hbs 模块构建失败:TypeError:无法读取null 的属性“path”
任何帮助将不胜感激。请随意提出澄清问题,因为我对webpack完全不熟悉。