0

I have a gulp task that concats and uglifies the js files when changed. If I only use one source, it works. I am learning angular however, and want it to concat the modules first so similar to this:

https://medium.com/@dickeyxxx/best-practices-for-building-angular-js-apps-266c1a4a6917#.mujtfmj63

I am using:

gulp.task('scripts', function(){
    return gulp.src(path.gulp.paths.src + ['/**/module.js', '/**/*.js'])
    .pipe(concat('all.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest(path.gulp.paths.dist));
  });

and the gulp task runs but it does not create the all.min.js file. If I remove the array and just use this it works:

gulp.task('scripts', function(){
    return gulp.src(path.gulp.paths.src + '/**/*.js')
    .pipe(concat('all.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest(path.gulp.paths.dist));
  });

My directory is set up as

public
 |  
 +-- modules
 |  |  
 |  +-- module.js
 +-- test.js

What am I doing wrong?

Mike
  • 753
  • 1
  • 11
  • 25
  • See also http://stackoverflow.com/questions/21386940/why-does-gulp-src-not-like-being-passed-an-array-of-complete-paths-to-files –  Dec 31 '15 at 20:38

1 Answers1

1

You're trying to add path.gulp.paths.src (which I assume is a string) to an array. For this operation, JavaScript first converts the array to a string (see https://stackoverflow.com/a/7124907). Assuming your string is './public', what you end up passing to gulp.src is './public/**/module.js,/**/*.js', which is not a valid path.

You could prepend the string to each element of the array ([path.gulp.paths.src + '/**/module.js', path.gulp.paths.src + '/**/*.js']), or you can use the cwd option to just set it as the base for all your files:

return gulp.src(['/**/module.js', '/**/*.js'], {cwd: path.gulp.paths.src})
...
Community
  • 1
  • 1
Igor Dubinskiy
  • 376
  • 1
  • 6