Gulp-uglify将多个javascript文件合并为一个javascript文件

时间:2023-01-24 11:28:17

I'm searching for Gulp task that can take multiple javascript files into a single javascript file and compress to one file, like grunt-contrib-uglify.

我正在寻找可以将多个javascript文件放入单个javascript文件并压缩到一个文件的Gulp任务,例如grunt-contrib-uglify。

This what I tried to do so for to simulate grunt-contrib-uglify:

这就是我试图模拟grunt-contrib-uglify:

gulp.task('compressJS', function ()
{
    return gulp.src(SomeJSArrayWithALotOfFiles)
        .pipe(concat('application.js'))
        .pipe(rename({suffix: '.min'}))
        .pipe(uglify())
        .pipe(gulp.dest('../application'))
}

My problem with this solution:
I need manually delete the file (application.js.min) before I run the task, otherwise every task execution the new files concatenate to old compressed file (because this line: .pipe(concat('application.js'))).

我的解决方案的问题:我需要在运行任务之前手动删除文件(application.js.min),否则每个任务执行新文件都会连接到旧的压缩文件(因为这行:.pipe(concat('application。 JS')))。

1 个解决方案

#1


3  

In your SomeJSArrayWithALotOfFiles, exclude all files that end with .min.js.

在SomeJSArrayWithALotOfFiles中,排除以.min.js结尾的所有文件。

As array, including all .js, but excluding .min.js files:

作为数组,包括所有.js,但不包括.min.js文件:

[ '**/*.js', '!**/*.min.js' ]

Or as single string, including all .js files not ending in .min.js:

或者作为单个字符串,包括不以.min.js结尾的所有.js文件:

'**/*!(.min).js'

#1


3  

In your SomeJSArrayWithALotOfFiles, exclude all files that end with .min.js.

在SomeJSArrayWithALotOfFiles中,排除以.min.js结尾的所有文件。

As array, including all .js, but excluding .min.js files:

作为数组,包括所有.js,但不包括.min.js文件:

[ '**/*.js', '!**/*.min.js' ]

Or as single string, including all .js files not ending in .min.js:

或者作为单个字符串,包括不以.min.js结尾的所有.js文件:

'**/*!(.min).js'