【问题标题】:Changing output directories/files to lowercase in Gulp在 Gulp 中将输出目录/文件更改为小写
【发布时间】:2016-03-24 07:24:05
【问题描述】:

我正在使用 Gulp 自动复制/捆绑/编译我的文件,我基本上将整个文件夹结构从基本文件夹 (MyProject/Scripts) 复制到 wwwroot/js。

在复制/处理过程中,我想将输出路径/文件名重命名为小写。我找到了 ChangeCase-module 和 Rename-module,但我无法在下面的设置中使用它。

gulp.task("compile:less", function () {
    return gulp.src(paths.lessSrc)
        .pipe(less())
        //how can I get to currentdirectory so I can use it for the rename? maybe there is another way
        //.pipe(rename({ dirname: changeCase.lowerCase(??currentdir??) }))
        .pipe(gulp.dest(paths.cssTarget));
});

gulp.task("compile:js", function () {
    return gulp.src(paths.jsOrigin)
        //simple copy of folders and files but how to rename all to lowercase?
        .pipe(gulp.dest(paths.jsTarget));
});

【问题讨论】:

  • 你试过把那种语法:dirname:changeCase.lowerCase()?所以你只需使用函数来重命名目录名。
  • 没试过,但下面的回答有效:) 还是谢谢

标签: gulp gulp-less asp.net-core-1.0 gulp-rename task-runner-explorer


【解决方案1】:

您可以将回调函数传递给gulp-rename

gulp.task("compile:js", function () {
  return gulp.src(paths.jsOrigin)
    .pipe(rename(function(path) {
       path.dirname = changeCase.lowerCase(path.dirname);
       path.basename = changeCase.lowerCase(path.basename);
       path.extname = changeCase.lowerCase(path.extname);
     })) 
    .pipe(gulp.dest(paths.jsTarget));
});

【讨论】:

  • 而不是path.dirname = changeCase.lowerCase(path.dirname); path.basename = changeCase.lowerCase(path.basename); path.extname = changeCase.lowerCase(path.extname); 我认为应该是:path.dirname = path.dirname.toLowerCase(); path.basename = path.basename.toLowerCase(); path.extname = path.extname.toLowerCase();
猜你喜欢
  • 1970-01-01
  • 2012-10-14
  • 1970-01-01
  • 1970-01-01
  • 2016-11-10
  • 1970-01-01
  • 1970-01-01
  • 2015-01-25
  • 1970-01-01
相关资源
最近更新 更多