目录结构:
plopfile.js中使用helper,引入助手文件helper.js (使用require引入)
const helpler = require('./plop_template/script/helper')
module.exports = function (plop) {
helpler(plop)
}
helper.js中:
module.exports = function (plop) {
plop.setHelper('eachIndex', function (context, options) { // 助手代码
let ret = ''
for (let i = 0, j = context.length; i < j; i++) {
ret = ret + options.fn({ it: context[i], isLast: i == context.length - 1 })
}
return ret
})
}