0

When running the final build step in GULP, I am trying to use uglify with a wildcard in the gulp.src, but seeing an error.

This works:

gulp.task('build', ['lint','karma','clean'], function () {
return gulp.src('./src/js/file.js')
    .pipe(gulp.dest('./dist'))
    .pipe(uglify())
    .pipe(size())
    .pipe(gulp.dest('./dist'));
});

But this doesn't:

gulp.task('build', ['lint','karma','clean'], function () {
return gulp.src('./src/js/*.js')
    .pipe(gulp.dest('./dist'))
    .pipe(uglify())
    .pipe(size())
    .pipe(gulp.dest('./dist'));
});

The only difference being that I select a specific file in the working gulp.src, but use a wildcard in the non-working version. I have narrowed this down to uglify() because if I comment it out, I don't get the error, and everything completes without issue.

Any help would be greatly appreciated

Andrew R.
  • 285
  • 3
  • 12
  • Why do you call `gulp.dest` twice in the same pipeline? Does removing the first one solve the problem? – Jamie Dixon Sep 28 '15 at 23:27
  • There is no change. From what I understood (still new to GULP), this was to set where the data was to be placed while the rest of the operations were performed, then the second one was where the final output was located. It may not be necessary, but I have seen the example in several gulp files. – Andrew R. Sep 28 '15 at 23:36
  • 1
    Sometimes it's required to put the files in once place, transform them, and then store them in another. Here though you're just storing them in the same place so no need for the first call to `gulp.dest`. What's the error you're getting? – Jamie Dixon Sep 28 '15 at 23:39
  • And that makes sense. The error is: `events.js:85 throw er; // Unhandled 'error' event` with all of the corresponding reference to differing lines in: `events.js:85 throw er; // Unhandled 'error' event ^ /Users/andrewr/Development/viper-probe-droid/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js` – Andrew R. Sep 28 '15 at 23:44
  • Looks like there's an unexpected character in one of your JS files. Do you have minified files or source maps in the `src/js` folder also? – Jamie Dixon Sep 28 '15 at 23:47
  • The final comment here: https://github.com/terinjokes/gulp-uglify/issues/76 suggests using `gulp-util` to log the error. This person seems to have had a similar issue also: http://stackoverflow.com/questions/28003104/uglify-throws-parse-error – Jamie Dixon Sep 28 '15 at 23:48
  • It's 1am here so I'm off for the night. I hope those links help. – Jamie Dixon Sep 28 '15 at 23:49
  • Thanks! It turned out to be a closing block comment (*/) which was causing the issue. I will be adding the gulp-util back in, but wasn't going to until I have the rest working. It's working now. – Andrew R. Sep 28 '15 at 23:52

0 Answers0