It seems in many places the professionals are building their projects using a node.js script that involves either gulp or grunt. What I can't figure out though, is why the script method is preferrable? When switching from the command line version to the script version, you add other packages in: i.e. gulp-uglify, vinyl-source-stream and vinyl-buffer. Wouldn't it be safer long-term-wise to use a method with the least amount of dependencies? Take for example the following command line method which I am currently using:
browserify entry.js | uglifyjs > bundle.js
This relies on browserify and uglifyjs, and I don't have the additional dependencies of gulp, gulp-uglifyjs, etc... and I don't have to worry about the version of gulp-uglifyjs relative to the straight uglifyjs at npm. Now see the following version:
var browserify = require('browserify');
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
gulp.task('browserify', function() {
return browserify('./source/scripts/app.js')
.bundle()
.pipe(source('bundle.js')) // gives streaming vinyl file object
.pipe(buffer()) // <----- convert from streaming to buffered vinyl file object
.pipe(uglify()) // now gulp-uglify works
.pipe(gulp.dest('./build/scripts'));
});
It seems so much more complex, but for what reason would this ever be a more efficient and safer way to build a javascript project? Thanks.