【问题标题】:Gulp dest() dynamic destination folders based on file namesGulp dest() 基于文件名的动态目标文件夹
【发布时间】:2016-10-27 19:25:50
【问题描述】:

例如,我想遍历所有 src 文件并将每个文件移动到以文件名本身命名的文件夹中。

来自:

hello.js
omg.js

到:

hello/
  hello.js
omg/
  omg.js

我有这个任务:

gulp.src('/*.js')
  .pipe(gulp.dest('/' + filename here.......));

我如何做到这一点?

【问题讨论】:

    标签: javascript node.js file directory gulp


    【解决方案1】:
    gulp.task('pack', function () {
      return gulp.src('temp/**/*.js')
        .pipe(uglify())
        .pipe(rename(function (path) {
            path.dirname += "/"+path.basename;
            path.extname = ".min.js";
        }))
        .pipe(gulp.dest('./build'));
    });
    

    【讨论】:

    • 此代码将移动文件并将其重命名为 .min.js 如果您不想要该功能,那么您可以跳过正在重命名它的管道。
    • 我正在尝试根据文件名设置动态目标文件夹....我不会是固定目标:D
    猜你喜欢
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-20
    • 2023-03-17
    • 1970-01-01
    • 2015-12-01
    相关资源
    最近更新 更多