Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

coffeescript - gulp, browserify, maps?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...