gulp-uglify无法更改名称 [英] gulp-uglify cannot change the name

查看:314
本文介绍了gulp-uglify无法更改名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gulp-uglify来缩小我的代码,还有一件事我想改变。



我有下一个 gulpfile.js 。当我执行 gulp calendar-uglify 时,我得到了编译内部/编译/目录以及名称 calendar.min.js 。如果我在 uglify 内更改名称,然后再次运行命令,gulp会再次生成该名称。



我的意思是,uglify似乎无法用我写的名字来编译文件。 gulp-uglify allways会获取concat文件的文件名。



我能做些什么来改变它?



TY,

Jaster

gulpfile.js $ b

  //依赖
var gulp = require('gulp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify');

//私有回调

/ **
* 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'));
};
$ b $ **
*日历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 /'));
};

//任务def

gulp.task('calendar-concat',_calendarConcat);
gulp.task('calendar-uglify',_calendarUglify);


解决方案

gulp-uglify 文档没有明确说明 uglify()任何地方,但你可以看看源代码来弄清楚。它基本上是这样的:

  uglify([opts,[uglify]])

其中



因此,使用 uglify无法指定不同的文件名()



反正没有必要这样做。 Gulp插件应该做好一件事,一件事。这样你可以将它们组合成更复杂的管道。



在你的情况下,你正在寻找 gulp-rename 插件让你重新命名一个文件:

  var rename = require('gulp-rename'); 

var _calendarUglify = function(){
return gulp.src('./ dist / calendar.min.js')
.pipe(uglify({
mangle:true,
输出:{
美化:true
}
}))
//将文件重命名为calendar2.min.js
。 pipe(rename({basename:'calendar2.min'}))
.pipe(gulp.dest('./ compile /'));
};


I'm using gulp-uglify to minify my code, and there's a thing I would like to change .

I have the next gulpfile.js . When I do gulp calendar-uglify I got the compile inside /compile/ directory and with the name calendar.min.js. If I change the name inside uglify and I run again the command, gulp generates the name before again.

I mean, it seems that uglify cannot compile the file with the name I wrote. Gulp-uglify allways takes the filename of the concat file.

What can I do to change that?

TY,

Jaster

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);

解决方案

The gulp-uglify documentation doesn't explicitly state the method signature for uglify() anywhere, but you can look at the source code to figure it out. It's essentially this:

uglify([opts, [uglify]])

Where

So there's no way specify a different file name using uglify().

There's no need for that anyway. Gulp plugins are supposed to do one thing and one thing well. That way you can combine them into more complex pipelines.

In your case you're looking for the gulp-rename plugin which let's you rename a file:

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无法更改名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆