【问题标题】:How can gulp-load-plugins replace all gulp- to ggulp-load-plugins 如何将所有 gulp- 替换为 g
【发布时间】:2018-04-20 00:17:12
【问题描述】:

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

但是如何让 gulp-load-plugins 默认将所有以gulp- 开头的插件名称替换为g

例如

gulp-sass

other-gulp-plugin

重命名为

gSass

other-gulp-plugin

【问题讨论】:

    标签: gulp gulp-load-plugins


    【解决方案1】:

    来自gulp-load-plugins options

    pattern: ['gulp-', 'gulp.', '@/gulp{-,.}'], // glob(s)搜索

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

    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(-|.)(.)/, 'g\U$2\E');
    
       // but try this 
        return name.replace(/^@*gulp(-|.)(.)/, function (match, p1, p2) {
           return "g" + p2.toUpperCase(); })
       // p2 is the second capture group
       }
    });
    

    简单案例:

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

    我将简单的案例留给说明,但您可能需要在 node/gulp 中更长的未注释版本。

    【讨论】:

      猜你喜欢
      • 2015-04-06
      • 2015-01-29
      • 2016-05-23
      • 1970-01-01
      • 2019-04-29
      • 2015-05-31
      • 2016-01-28
      • 2015-06-19
      • 1970-01-01
      相关资源
      最近更新 更多