gulp-uglify 无法更改名称
gulp-uglify cannot change the name
我正在使用 gulp-uglify 来缩小我的代码,有一点我想更改。
我有下一个gulpfile.js
。当我执行 gulp calendar-uglify
时,我在 /compile/ 目录中得到了编译,名称为 calendar.min.js
。如果我更改 uglify
中的名称并再次 运行 命令,gulp 会再次生成之前的名称。
我的意思是,uglify好像不能编译我写的这个名字的文件。 Gulp-uglify 总是采用 concat 文件的文件名。
我能做些什么来改变它?
TY,
贾斯特
gulpfile.js
// Dependencies
var gulp = require('gulp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify');
// Private callbacks
/**
* Calendar js concat
* @private
**/
var _calendarConcat = function(){
return gulp.src(['./src/olympics/Calendar.js', './src/entry/calendar.js'])
.pipe(concat('calendar.min.js'))
.pipe(gulp.dest('./dist'));
};
/**
* Calendar js uglify
* @private
**/
var _calendarUglify = function(){
return gulp.src('./dist/calendar.min.js')
.pipe(uglify('calendar.min.js', {
mangle: true,
output: {
beautify: true
}
}))
.pipe(gulp.dest('./compile/'));
};
// Task def
gulp.task('calendar-concat', _calendarConcat);
gulp.task('calendar-uglify', _calendarUglify);
gulp-uglify
documentation doesn't explicitly state the method signature for uglify()
anywhere, but you can look at the source code自己想办法。本质上是这样的:
uglify([opts, [uglify]])
在哪里
opts
是 options 的可选映射。
uglify
是可选的 instance of uglifyJs
因此无法使用 uglify()
指定不同的文件名。
反正也没必要。 Gulp 插件应该做好一件事和一件事。这样您就可以将它们组合成更复杂的管道。
在您的情况下,您正在寻找 gulp-rename
plugin 让您重命名文件:
var rename = require('gulp-rename');
var _calendarUglify = function(){
return gulp.src('./dist/calendar.min.js')
.pipe(uglify({
mangle: true,
output: {
beautify: true
}
}))
// renames the file to calendar2.min.js
.pipe(rename({basename:'calendar2.min'}))
.pipe(gulp.dest('./compile/'));
};
我正在使用 gulp-uglify 来缩小我的代码,有一点我想更改。
我有下一个gulpfile.js
。当我执行 gulp calendar-uglify
时,我在 /compile/ 目录中得到了编译,名称为 calendar.min.js
。如果我更改 uglify
中的名称并再次 运行 命令,gulp 会再次生成之前的名称。
我的意思是,uglify好像不能编译我写的这个名字的文件。 Gulp-uglify 总是采用 concat 文件的文件名。
我能做些什么来改变它?
TY,
贾斯特
gulpfile.js
// Dependencies
var gulp = require('gulp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify');
// Private callbacks
/**
* Calendar js concat
* @private
**/
var _calendarConcat = function(){
return gulp.src(['./src/olympics/Calendar.js', './src/entry/calendar.js'])
.pipe(concat('calendar.min.js'))
.pipe(gulp.dest('./dist'));
};
/**
* Calendar js uglify
* @private
**/
var _calendarUglify = function(){
return gulp.src('./dist/calendar.min.js')
.pipe(uglify('calendar.min.js', {
mangle: true,
output: {
beautify: true
}
}))
.pipe(gulp.dest('./compile/'));
};
// Task def
gulp.task('calendar-concat', _calendarConcat);
gulp.task('calendar-uglify', _calendarUglify);
gulp-uglify
documentation doesn't explicitly state the method signature for uglify()
anywhere, but you can look at the source code自己想办法。本质上是这样的:
uglify([opts, [uglify]])
在哪里
opts
是 options 的可选映射。uglify
是可选的 instance of uglifyJs
因此无法使用 uglify()
指定不同的文件名。
反正也没必要。 Gulp 插件应该做好一件事和一件事。这样您就可以将它们组合成更复杂的管道。
在您的情况下,您正在寻找 gulp-rename
plugin 让您重命名文件:
var rename = require('gulp-rename');
var _calendarUglify = function(){
return gulp.src('./dist/calendar.min.js')
.pipe(uglify({
mangle: true,
output: {
beautify: true
}
}))
// renames the file to calendar2.min.js
.pipe(rename({basename:'calendar2.min'}))
.pipe(gulp.dest('./compile/'));
};