4

I'm working on a project that uses the following tools:

I'm able to generate the distribution file and it works correctly. The generated source map is not correct though. When I load it in Chrome, Chrome not able to map the distribution file to the source files. My problem is similar (but not the same) to this one. Unfortunately, this similar issue doesn't have an answer, thus it doesn't help me.

I've also tried to follow this recipe, but it doesn't fit my case.

This is the relevant code of my set up (gulpfile.js):

var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');

gulp.task('build:dist', function() {
   var browserifyInstance = browserify({
      entries: 'src/module.js',
      debug: true,
      standalone: 'Module',
      bundleExternal: false,
      transform: [babelify]
   });

   return browserifyInstance
      .bundle()
      .pipe(source('module.js'))
      .pipe(rename({
         extname: '.min.js'
      }))
      .pipe(buffer())
      .pipe(sourcemaps.init({
         loadMaps: true
      }))
      .pipe(uglify())
      .pipe(sourcemaps.write('./'))
      .pipe(gulp.dest('dist'));
});

How can I fix it?

Community
  • 1
  • 1
Aurelio De Rosa
  • 21,856
  • 8
  • 48
  • 71
  • I know my comment is not very constructive; but just one question: why would you want sourcemaps on a build distribution ? I mean, why would you uglify file and include sourcemaps ? If you uglify, that means you want to "obscure" your code, so, why sourcemaps ? – avcajaraville Dec 14 '15 at 09:08
  • 2
    Minification is not to obscure code, it's to save bandwidth to your users. The less the size, the faster the loading time of your website. – Aurelio De Rosa Dec 14 '15 at 11:58
  • Yeah, well, I know that, but why would you need them on a production environment ? Use them locally was my point... – avcajaraville Dec 14 '15 at 13:18
  • 2
    Sometimes you have a bug that happens in production but not on your machine/stage machine. With source maps you can easy find the problem. – Aurelio De Rosa Dec 14 '15 at 13:52
  • Ok, it seems like is a common thing so far: https://github.com/terinjokes/gulp-uglify/issues/64 Thats why I was suggesting not to use sourcemaps on prod. but if there is no other option, you have to check that issue and see what you can do. Good luck :) – avcajaraville Dec 14 '15 at 13:56

0 Answers0