gulp-load插件如何取代所有gulp-to-g



默认的gull-load插件删除所有插件名称gulp-

但是如何让gull-load插件默认替换所有以gulp-g开头的插件名称呢?

例如

gulp-sass
other-gulp-plugin

重命名为

gSass
other-gulp-plugin

从gull加载插件选项:

pattern:['gulp-','gulp.'、'@/gulp{-,.}'],//用于搜索的glob

replaceString:/^gump(-|.)/,//将模块添加到上下文时从模块名称中删除什么

renameFn:function(name){…},//一个处理插件重命名的函数(默认工作)

所以你需要这样的东西(即,未经测试的)

var plugins = require("gulp-load-plugins")({
renameFn: function(name) {
//  if only it were as easy as the below : the simple case
//  return name.replace(/^@*gulp(-|.)(.)/, 'gU$2E');
// but try this 
return name.replace(/^@*gulp(-|.)(.)/, function (match, p1, p2) {
return "g" + p2.toUpperCase(); })
// p2 is the second capture group
}
});

简单案例:

  1. /@*gullow(-|.):找到模式@gullow-,@gullow。,大口大口
  2. (.):捕获下一个字符
  3. g\U$2\E:仅将第二个捕获组(.)替换为
  4. 'g'后跟大写\U第二捕获组$2和
  5. 第二个捕获组的末尾大写\E[在您的情况下并不需要,因为您只需要一个字符]

我保留了简单的大小写作为说明,但您可能需要node/gulp中较长的未注释版本。

最新更新