我限制不使用gulp-uglify
任务。我想创建一个运行以下uglify-js
命令的gulp任务:
./node_modules/.bin/uglifyjs ./public/dist/js/myfile.js -o ./public/dist/js/myfile.min.js --comments='/customComments/'
有没有办法在不使用gulp-uglify
任务的情况下执行此操作?
答案 0 :(得分:1)
您可以使用Node.js-builtin child_process.spawn()
直接执行命令:
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();
});
});