简体   繁体   中英

How to bundle a non-minified and minified js files with browserify

I get a minified bundle file, i want to get a non-minified bundle with it in the same 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']);
});

EDIT: Actually, I don't think this can be done in one pipe, we could have two, one which doesn't minify, and one which minifies and source maps:

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));

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM