Reputation: 10691
I have a restriction of not using the gulp-uglify
task. I want to create a gulp task that runs the following uglify-js
command:
./node_modules/.bin/uglifyjs ./public/dist/js/myfile.js -o ./public/dist/js/myfile.min.js --comments='/customComments/'
Is there a way to do that without using the gulp-uglify
task?
Upvotes: 0
Views: 280
Reputation: 30574
You can use the Node.js-builtin child_process.spawn()
to execute the command directly:
var gulp = require('gulp');
var spawn = require('child_process').spawn;
gulp.task('default', function(done) {
var uglifyjs = spawn('./node_modules/.bin/uglifyjs', [
'./public/dist/js/myfile.js',
'-o', './public/dist/js/myfile.min.js',
"--comments='/customComments/'"
]);
uglifyjs.stderr.on('data', function(data) {
console.error(data.toString());
});
uglifyjs.on('close', function(code) {
if (code !== 0) {
done('uglifyjs exited with code ' + code);
return;
}
done();
});
});
Upvotes: 1