plop开发模板引入一个Handlebars助手代码文件

目录结构:

在这里插入图片描述

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
	  })
}

猜你喜欢

转载自blog.csdn.net/qq_29184685/article/details/120161398