我正在尝试编译 Components/client 文件夹内的 .hbs 文件。编译工作正常。
我在部分名称中添加子文件夹名称时遇到问题。
这是我的代码。
handlebars: {
build: {
options: {
partialRegex: /.*/,
partialsPathRegex: /\/components\/client\//,
namespace: 'tmpl',
processName: function(filePath) {
// Extract subfolder name and join it with the file name (excluding extension)
var subfolderMatch = filePath.match(/\/([^\/]*)\/[^\/]*\.hbs$/);
var subfolder = subfolderMatch ? subfolderMatch[1] + '/' : '';
return subfolder + filePath.replace(/^.*[\\\/]/, '').replace('.hbs', '');
},
},
files: {
'public/js/tmpl.js': ['views/components/client/*.hbs', 'views/components/client/**/*.hbs'],
},
},
}
找到答案了。
试试这个。
handlebars: {
build: {
options: {
partialRegex: /.*/,
partialsPathRegex: /\/components\/client\//,
namespace: 'tmpl',
processPartialName: function(filePath) {
var subfolderMatch = filePath.match(/\/([^\/]*)\/[^\/]*\.hbs$/);
var subfolder = subfolderMatch ? subfolderMatch[1] : '';
var fileName = filePath.replace(/^.*[\\\/]/, '').replace('.hbs', '');
if (subfolder !== 'client') {
fileName = subfolder + '-' + filePath.replace(/^.*[\\\/]/, '').replace('.hbs', '');
}
return fileName;
},
},
files: {
'public/js/tmpl.js': ['views/components/client/*.hbs', 'views/components/client/**/*.hbs'],
},
},
}