gulp, browserify, maps?

二次信任 提交于 2019-11-26 21:22:04

问题


How do I enable source maps? I'm doing this:

  var browserify = require("gulp-browserify")

  gulp.task("compile:client", function() {
    gulp.src("src/client/app.coffee", {
      read: false
    })
    .pipe(browserify({
      debug: true // THIS DOES NOTHING :(
      transform: ['coffeeify'],
      extensions: ['.coffee']
    }))
    .pipe(rename('app.js'));
  });

Ouch... for some reason on the github page for gulp-browserify it says: PLUGIN IS BLACKLISTED.

I don't get it... how the heck I'm suppose to use browserify with my coffeescript files then?

UPD: Ha! I was wrong: debug option works. It just sticks source maps info right there into the output javascript file. Awesome. Still the question remains open: why this plugin in blacklisted?


回答1:


Have a look over here:

https://github.com/gulpjs/plugins/issues/47

and here:

https://github.com/gulpjs/gulp/issues/369

UPDATE:

I don't think this below is "messy".

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

var bundler = browserify('./js/index.js');

gulp.task('compile', function(){
  return bundler.bundle({standalone: 'noscope'})
    .pipe(source('noscope.js'))
    .pipe(gulp.dest('./dist'));
});



回答2:


I found a solution, by crawling the web, and it looks like this:

var browserify = require('browserify');
var gulp = require('gulp');
var exorcist = require('exorcist');
var source = require('vinyl-source-stream');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps'); // https://www.npmjs.org/package/gulp-sourcemaps

gulp.task('browserify', function(){
    return browserify({
            entries: ['./file1.js'],
            debug: true
        })
        .bundle()
        .pipe(exorcist('./output.js.map'))
        .pipe(source('output.js'))
        .pipe(gulp.dest('./'));
});

gulp.task('together', ['browserify'], function() {
  return gulp.src('output.js')
    .pipe(sourcemaps.init({loadMaps: true}))
      .pipe(concat('all-with-maps.js'))
      .pipe(uglify())
    .pipe(sourcemaps.write('.', {addComment: true /* the default */, sourceRoot: '/src'}))
    .pipe(gulp.dest('dist'));
});

Make sure you have a recent version of browserify installed (I use 5.10.0 as of today).. You used to need to pass {debug: true} to the bundle() call .. but it has moved to browserify() directly.

Regarding the blacklisting: it is thought to be better to use browserify() directly, as we do here. There's no need for a plugin it would seem.



来源:https://stackoverflow.com/questions/23667340/gulp-browserify-maps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!