Search code examples
gulpgulp-uglify

Gulp: uglify in different destination folder with same hierarchy inside


I am a newbie of gulp, just started now. I am confused in giving src and destination to my task. What i am try to do is to create a new minify destination folder with same inside hierarchy like below.

Current Folder Structure (originals files):

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

Minify Folder (where js file are minified):

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))
});

Solution

  • Try:

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

    and everything else as you have it and let me know if that works for you. In this case your components_min should replace the app folder - everything before the glob - and maintain your folder structure.