Gulp / uglify - bundle不会压缩到bundle.js

时间:2015-10-09 14:21:33

标签: gulp browserify gulp-uglify

这是我的代码

var gulp = require('gulp');
var browserify = require('gulp-browserify');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');

gulp.task('js', function () {
    gulp.src('js/main.js')
        .pipe(browserify())
        .pipe(rename('js/bundle.js'))
        .pipe(uglify())
        .pipe(gulp.dest('./'));

})

gulp.task('watch', function () {

    gulp.watch('js/*.js', ['js']);
})

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

var gulp =       require('gulp');
var browserify = require('gulp-browserify');
var uglify =     require('gulp-uglify');
var source =     require('vinyl-source-stream');

gulp.task(
    browserify('js/main.js')
    .bundle()
    .pipe(source('bundle.js'))
    .pipe(uglify())
    .pipe(gulp.dest('./'));
});

gulp.task('watch', function () {
    gulp.watch('js/*.js', ['js']);
})