Skip to content

Commit 515a9ea

Browse files
committed
Merge pull request jakemmarsh#124 from DrewML/fixSourcemaps
Fix sourcemaps for Browserify
2 parents 0e36074 + a91fb0a commit 515a9ea

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

gulp/tasks/browserify.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ import browserSync from 'browser-sync';
1717
import debowerify from 'debowerify';
1818
import ngAnnotate from 'browserify-ngannotate';
1919

20+
function createSourcemap() {
21+
return !global.isProd || config.browserify.prodSourcemap;
22+
}
23+
2024
// Based on: http://blog.avisi.nl/2014/04/25/how-to-keep-a-fast-build-with-browserify-and-reactjs/
2125
function buildScript(file) {
22-
23-
var bundler = browserify({
26+
27+
let bundler = browserify({
2428
entries: [config.sourceDir + 'js/' + file],
25-
debug: true,
29+
debug: createSourcemap(),
2630
cache: {},
2731
packageCache: {},
2832
fullPaths: !global.isProd
@@ -51,16 +55,16 @@ function buildScript(file) {
5155

5256
function rebundle() {
5357
const stream = bundler.bundle();
54-
const createSourcemap = global.isProd && config.browserify.prodSourcemap;
58+
const sourceMapLocation = global.isProd ? './' : '';
5559

5660
return stream.on('error', handleErrors)
5761
.pipe(source(file))
58-
.pipe(gulpif(createSourcemap, buffer()))
59-
.pipe(gulpif(createSourcemap, sourcemaps.init()))
62+
.pipe(gulpif(createSourcemap(), buffer()))
63+
.pipe(gulpif(createSourcemap(), sourcemaps.init({ loadMaps: true })))
6064
.pipe(gulpif(global.isProd, streamify(uglify({
6165
compress: { drop_console: true }
6266
}))))
63-
.pipe(gulpif(createSourcemap, sourcemaps.write('./')))
67+
.pipe(gulpif(createSourcemap(), sourcemaps.write(sourceMapLocation)))
6468
.pipe(gulp.dest(config.scripts.dest))
6569
.pipe(browserSync.stream({ once: true }));
6670
}

0 commit comments

Comments
 (0)