Gulp: 在内部具有相同层次结构的不同目标文件夹中进行 uglify

Gulp: uglify in different destination folder with same hierarchy inside

我是gulp的新手,才刚刚开始。我在为我的任务提供 src 和目的地时感到困惑。我想做的是创建一个新的缩小目标文件夹,其内部层次结构如下所示。

当前文件夹结构(原始文件):

app
-components
 --post-creator
  ---post-creator.component.js
 --post-rating
  ---post-rating.component.js
-routing_components
 --app-routing
  ---app-routing.component.js
 --user-routing
  ---user-routing.component.js

缩小文件夹(缩小js文件的地方):

minify_destination
-components
 --post-creator
  ---post-creator.component.js
 --post-rating
  ---post-rating.component.js
-routing_components
 --app-routing
  ---app-routing.component.js
 --user-routing
  ---user-routing.component.js

Gulpfile.js

var gulp = require('gulp'),
    uglify = require('gulp-uglify');
gulp.task('default', function () {
    gulp.src('app/components/*/*/*.js')
    .pipe(uglify())
    .pipe(gulp.dest(components_min))
});

尝试:

gulp.src('app/**/*.js')

以及您拥有的所有其他内容,如果这对您有用,请告诉我。在这种情况下,您的 components_min 应该替换 app 文件夹 - glob 之前的所有内容 - 并保持您的文件夹结构。