I have a gulp task to concatenate and minify my js files (in filesJs array) in a main file assets.min.js, but my files are not concatenated in order of my array ..
The code :
var gulp = require('gulp');
var gulpConcat = require('gulp-concat');
var gulpPlumber = require('gulp-plumber');
var gulpSourceMaps = require('gulp-sourcemaps');
var gulpUglify = require('gulp-uglify');
var pathSource = 'web/bundles/sf';
var pathSourceJs = pathSource + '/js';
var pathTarget = 'web/bundles/sf/build';
var pathTargetJs = pathTarget + '/js';
var filesJs = [
pathSourceJs + '/jquery.js',
pathSourceJs + '/jquery1.7.2.js',
pathSourceJs + '/jquery.themepunch.plugins.min.js',
pathSourceJs + '/jquery.themepunch.revolution.min.js',
pathSourceJs + '/jquery.stellar.js',
pathSourceJs + '/custom.js',
pathSourceJs + '/jquery.jcarousel.min.js',
pathSourceJs + '/waypoints.js',
pathSourceJs + '/jquery.easypiechart.min.js',
pathSourceJs + '/nimble.js',
pathSourceJs + '/scrollspy.js',
pathSourceJs + '/jquery.fancybox.pack.js',
pathSourceJs + '/jquery.appear.js',
pathSourceJs + '/bootstrap.js',
pathSourceJs + '/counters.js',
pathSourceJs + '/slider.js',
pathSourceJs + '/revolution.js',
pathSourceJs + '/contact.js',
pathSourceJs + '/html5shiv.js',
pathSourceJs + '/respond.min.js'
];
gulp.task('minify-javascript', function () {
return gulp.src(filesJs, {base: pathSource + '/'})
.pipe(gulpPlumber(function(error) {
console.log(error.toString());
this.emit('end');
}))
.pipe(gulpSourceMaps.init())
.pipe(gulpConcat(outputFileNameJs))
.pipe(gulpUglify())
.pipe(gulpSourceMaps.write('.'))
.pipe(gulp.dest(pathTargetJs));
});
The output file is minified in this order (bad order) instead of the order defined in filesJs array :
"sources":
[
"js/slider.js",
"js/contact.js",
"js/bootstrap.js",
"js/jquery.js",
"js/jquery1.7.2.js",
"js/jquery.themepunch.plugins.min.js",
"js/jquery.themepunch.revolution.min.js",
"js/jquery.stellar.js",
"js/custom.js",
"js/jquery.jcarousel.min.js",
"js/waypoints.js",
"js/jquery.easypiechart.min.js",
"js/nimble.js",
"js/scrollspy.js",
"js/jquery.fancybox.pack.js",
"js/jquery.appear.js",
"js/counters.js",
"js/revolution.js",
"js/html5shiv.js",
"js/respond.min.js"
]
The concat is in order, but not the minification.
I don't understand why ..
Thanks in advance for your help
If your js files have dependency on each other, gulpUglify
will possibly re-arrange the order.
Please try disabling functions hoisting:
.pipe(gulpUglify({
compress: {hoist_funs: false}
}))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.