【问题标题】:How to bundle a non-minified and minified js files with browserify如何使用 browserify 捆绑非缩小和缩小的 js 文件
【发布时间】:2015-11-13 13:13:37
【问题描述】:

我得到了一个缩小的捆绑文件,我想在同一个 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']);
});

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 啊,是的,源图,试试我修改后的答案
    • 它正在工作,但我仍然在 ar-string.js 文件中的一行中获取代码,这是 browserify 做的吗?
    • hmmm,我猜是这样,也许你可以在第一个管道中使用另一个插件,如 gulp-prettify,以使输出在多行上很好地格式化?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-13
    • 2014-11-26
    • 2013-06-27
    • 2012-06-28
    • 1970-01-01
    相关资源
    最近更新 更多