我正在尝试使用这些帖子在项目中使用把手:
https://n8d.at/blog/how-to-use-handlebars-in-sharepoint-framework-projects-spfx/ https://n8d.at/blog/first-handlebars-web-part-in-spfx/
在我的gulp.js文件中,我有这个代码来扩展Webpack
$timestring = "20180606T110000";
$timestamp = strtotime($timestring);
echo date("m/d/Y h:i:s A", $timestamp);
我在config文件夹下创建了一个名为copy-static.assets.json的新文件,其中包含以下代码:
build.configureWebpack.mergeConfig({
additionalConfiguration: (generatedConfiguration)=> {
generatedConfiguration.module.rules.push(
{ test: /\.hbs$/, loader: "handlebars-template-loader" } );
return generatedConfiguration;
}
});
build.initialize(gulp);
我的模板与.ts webpart文件处于同一级别,我像这样引用模板:
{"includeExtensions": ["hbs"]}
运行gulp serve时出现此错误:
var compiled = require('./test.hbs');
知道如何解决这个问题吗?
注意我正在使用Webpack 2.
答案 0 :(得分:0)
试试这个
const loaderRule = {
"use": [{
"loader": "handlebars-template-loader"
}],
"test": /\.hbs/
};
build.configureWebpack.mergeConfig({
additionalConfiguration: (generatedConfiguration) => {
generatedConfiguration.module.rules.push(loaderRule);
return generatedConfiguration;}
});