Skip to content

Instantly share code, notes, and snippets.

@tompazourek
Created June 17, 2016 22:22
Show Gist options
  • Save tompazourek/767e6b35a87c3a57e26db70fd7244a0f to your computer and use it in GitHub Desktop.
Save tompazourek/767e6b35a87c3a57e26db70fd7244a0f to your computer and use it in GitHub Desktop.
Browserify experiment
'use strict';
var gulp = require('gulp')
var path = require('path')
var uglify = require('gulp-uglify')
var vinylPaths = require('vinyl-paths');
var del = require('del')
var browserify = require('browserify');
var sourcemaps = require('gulp-sourcemaps');
var gutil = require('gulp-util');
var concat = require('concat-stream');
var file = require('gulp-file');
gulp.task('javascript', function() {
var b = browserify({
entries: ['./app/beep.js', './app/boop.js'],
debug: true
});
function write(filepath) {
return concat(function(content) {
// create new vinyl file from content and use the basename of the
// filepath in scope as its basename.
return file(path.basename(filepath), content, {
src: true
})
// write content to build directory
.pipe(sourcemaps.init({
loadMaps: true
}))
// Add transformation tasks to the pipeline here.
//.pipe(uglify())
.on('error', gutil.log)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/'));
});
}
b.plugin('factor-bundle', {
outputs: [write('beep.bundle.js'), write('boop.bundle.js')]
});
return b.bundle().pipe(write('common.bundle.js'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment