【发布时间】: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-load-plugins 删除所有插件名称gulp-
但是如何让 gulp-load-plugins 默认将所有以gulp- 开头的插件名称替换为g?
例如
gulp-sass
other-gulp-plugin
重命名为
gSass
other-gulp-plugin
【问题讨论】:
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
}
});
简单案例:
我将简单的案例留给说明,但您可能需要在 node/gulp 中更长的未注释版本。
【讨论】: