625999f337
This commit makes gulp unconditionally create external-file sourcemaps for dev builds. Currently dev builds create both external and inline sourcemaps, which seems to confuse browsers and often prevents maps from loading. Additionally, this enables 'loadMaps' for the gulp sourcemap plugin to make sure that all sourcemaps from browserify are moved into the external file, fixing maps for dependencies. Change-Id: I9fcb945d639a60c19c94d688ff26126c8f49e256
75 lines
1.9 KiB
JavaScript
75 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
var config = require('../config');
|
|
var gulp = require('gulp');
|
|
var gulpif = require('gulp-if');
|
|
var gutil = require('gulp-util');
|
|
var source = require('vinyl-source-stream');
|
|
var sourcemaps = require('gulp-sourcemaps');
|
|
var buffer = require('vinyl-buffer');
|
|
var streamify = require('gulp-streamify');
|
|
var watchify = require('watchify');
|
|
var browserify = require('browserify');
|
|
var babelify = require('babelify');
|
|
var uglify = require('gulp-uglify');
|
|
var handleErrors = require('../util/handleErrors');
|
|
var browserSync = require('browser-sync');
|
|
var ngAnnotate = require('browserify-ngannotate');
|
|
|
|
// Based on: http://blog.avisi.nl/2014/04/25/how-to-keep-a-fast-build-with-browserify-and-reactjs/
|
|
function buildScript(file) {
|
|
|
|
var bundler = browserify({
|
|
entries: config.browserify.entries,
|
|
debug: true,
|
|
cache: {},
|
|
packageCache: {},
|
|
fullPaths: true
|
|
}, watchify.args);
|
|
|
|
if ( !global.isProd ) {
|
|
bundler = watchify(bundler);
|
|
bundler.on('update', function() {
|
|
rebundle();
|
|
});
|
|
}
|
|
|
|
var transforms = [
|
|
babelify,
|
|
ngAnnotate,
|
|
'brfs',
|
|
'bulkify'
|
|
];
|
|
|
|
transforms.forEach(function(transform) {
|
|
bundler.transform(transform);
|
|
});
|
|
|
|
function rebundle() {
|
|
var stream = bundler.bundle();
|
|
var createSourcemap = config.browserify.sourcemap;
|
|
|
|
gutil.log('Rebundle...');
|
|
|
|
return stream.on('error', handleErrors)
|
|
.pipe(source(file))
|
|
.pipe(gulpif(createSourcemap, buffer()))
|
|
.pipe(gulpif(createSourcemap, sourcemaps.init({ loadMaps: true })))
|
|
.pipe(gulpif(global.isProd, streamify(uglify({
|
|
compress: { drop_console: true }
|
|
}))))
|
|
.pipe(gulpif(createSourcemap, sourcemaps.write('./')))
|
|
.pipe(gulp.dest(config.scripts.dest))
|
|
.pipe(browserSync.reload({ stream: true, once: true }));
|
|
}
|
|
|
|
return rebundle();
|
|
|
|
}
|
|
|
|
gulp.task('browserify', function() {
|
|
|
|
return buildScript('main.js');
|
|
|
|
});
|