本文介绍了Gulp,concat和uglify文件,并与供应商concat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用gulp合并并丑化我的JS文件.之后,我想使用供应商文件夹(包括jquery,bootstrap,...
I want to concat and uglify my JS files with gulp. After that I want to conact the result with a vendor folder which includes jquery, bootstrap, ...
在丑化我的js代码后如何从供应商文件夹中合并文件?
How can I concat the files from the vendor folder after uglify my js code?
这是我当前的gulp文件:
Here is my current gulp file:
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
gulp.task('scripts', function() {
gulp.src([
'./src/resources/assets/js/**/*.js',
'!./src/resources/assets/js/vendor/**/*.js'
])
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(gulp.dest('./public/js/'));
});
gulp.task('default', ['scripts'], function() {
});
推荐答案
如果我正确理解了您的问题,那么您想使用库来连接js.files,但是要保留自己的js的concat版本?
if I understand your question correctly, you want to concat your js.files with the libraries, but keep a concat version of your own js ?
我愿意,您可以保留两个文件:
I would do that, you get to keep both files :
var runSequence = require('run-sequence');
gulp.task('myJs', function() {
gulp.src([
'./src/resources/assets/js/**/*.js',
'!./src/resources/assets/js/vendor/**/*.js'
])
.pipe(concat('myJs.js'))
.pipe(uglify())
.pipe(gulp.dest('./public/js/'));
});
gulp.task('allJs', function() {
gulp.src([
'./src/resources/assets/js/vendor/**/*.js',
'./public/js/myJs.js'
])
.pipe(concat('allJs.js'))
.pipe(uglify())
.pipe(gulp.dest('./public/js/'));
})
gulp.task('default', function() {
runSequence('myJs',
'allJs',
);
});
或者那样,您只保留一个文件:
or that, you only keep one file :
var merge = require('merge2');
gulp.task('scripts', function() {
// Get your js
var myJs = gulp.src([
src + 'my/*.js',
src + '!not/my/*.js'])
// Get vendor js
var vendorJs = gulp.src(src + 'not/my/*.js')
return merge(myJs, vendorJs)
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(gulp.dest(dest));
});
这篇关于Gulp,concat和uglify文件,并与供应商concat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!