Using Gulp to Concatenate and Uglify files

后端 未结 6 2204
一生所求
一生所求 2020-11-27 09:39

I\'m trying to use Gulp to:

  1. Take 3 specific javascript files, concatenate them, then save the result to a file (concat.js)
  2. Take this concatenated file
6条回答
  •  清歌不尽
    2020-11-27 10:29

    var gulp = require('gulp');
    var concat = require('gulp-concat');
    var uglify = require('gulp-uglify');
    
    gulp.task('create-vendor', function () {
    var files = [
        'bower_components/q/q.js',
        'bower_components/moment/min/moment-with-locales.min.js',
        'node_modules/jstorage/jstorage.min.js'
    ];
    
    return gulp.src(files)
        .pipe(concat('vendor.js'))
        .pipe(gulp.dest('scripts'))
        .pipe(uglify())
        .pipe(gulp.dest('scripts'));
    });
    

    Your solution does not work because you need to save file after concat process and then uglify and save again. You do not need to rename file between concat and uglify.

提交回复
热议问题