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, ...
How can I concat the files from the vendor folder after uglify my js code?
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() {
});
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));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With