forked from gulpjs/gulp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Browserify + Uglify2 with sourcemaps | ||
|
||
[Browserify](http://github.com/substack/node-browserify) has become an important and indispensable | ||
tool but requires being wrapped before working well with gulp. Below is a simple recipe for using | ||
Browserify with transforms and full sourcemaps that resolve to the original individual files. | ||
|
||
``` javascript | ||
'use strict'; | ||
|
||
var browserify = require('browserify'); | ||
var gulp = require('gulp'); | ||
var source = require('vinyl-source-stream'); | ||
var buffer = require('vinyl-buffer'); | ||
var uglify = require('gulp-uglify'); | ||
var sourcemaps = require('gulp-sourcemaps'); | ||
|
||
var getBundleName = function () { | ||
var version = require('./package.json').version; | ||
var name = require('./package.json').name; | ||
return version + '.' + name + '.' + 'min'; | ||
}; | ||
|
||
gulp.task('javascript', function() { | ||
|
||
var bundler = browserify({ | ||
entries: ['./app.js'], | ||
debug: true | ||
}); | ||
|
||
var bundle = function() { | ||
return bundler | ||
.bundle() | ||
.pipe(source(getBundleName() + '.js')) | ||
.pipe(buffer()) | ||
.pipe(sourcemaps.init({loadMaps: true})) | ||
// Add transformation tasks to the pipeline here. | ||
.pipe(uglify()) | ||
.pipe(sourcemaps.write('./')) | ||
.pipe(gulp.dest('./dist/js/')); | ||
}; | ||
|
||
return bundle(); | ||
}); | ||
``` |