如何使用browserify捆绑非缩小和缩小的js文件

时间:2015-11-13 13:13:38

标签: javascript node.js gulp browserify gulp-uglify

我得到一个缩小的捆绑文件,我希望在同一个dist中得到一个非缩小的捆绑包。

gulpfile.js

'use strict';


var gulp        = require('gulp'),
    gulpLoad    = require('gulp-load-plugins'),
    browserify  = require('browserify'),
    source      = require('vinyl-source-stream'),
    buffer      = require('vinyl-buffer'),
    del         = require('del'),
    pkg         = require('./package.json'),
    $           = gulpLoad(),
    DIST        = './dist',
    SRC         = './src/index.js';


gulp.task('clean', function(fn) {
  return del(DIST, fn);
})


gulp.task('lint', function() {
  return gulp.src(SRC)
    .pipe($.jshint())
    .pipe($.jshint.reporter('default'))
});


gulp.task('bundle', ['lint', 'clean'], function() {
  var b = browserify();

  return b.bundle()
    .pipe(source('./ar-string.min.js'))
    .pipe(buffer())
    .pipe($.sourcemaps.init({loadMaps: true}))
        .pipe($.uglify())
        .on('error', $.util.log)
    .pipe($.sourcemaps.write('./'))
    .pipe(gulp.dest(DIST));
});


gulp.task('default', function() {
  gulp.watch([SRC, './gulpfile.js'], ['bundle']);
});

1 个答案:

答案 0 :(得分:2)

编辑:实际上,我不认为这可以在一个管道中完成,我们可以有两个,一个不缩小,一个缩小和源地图:

b.bundle()
.pipe(source('./ar-string.js'))
.pipe(gulp.dest(DIST));

return b.bundle()
.pipe(source('./ar-string.min.js'))
.pipe(buffer())
.pipe($.sourcemaps.init({loadMaps: true}))
    .pipe($.uglify())
    .on('error', $.util.log)
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest(DIST));