-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
70 lines (58 loc) · 1.88 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var browserify = require('browserify')
var del = require('del')
var gulp = require('gulp')
var source = require('vinyl-source-stream')
var header = require('gulp-header')
var jshint = require('gulp-jshint')
var rename = require('gulp-rename')
var plumber = require('gulp-plumber')
var react = require('gulp-react')
var streamify = require('gulp-streamify')
var uglify = require('gulp-uglify')
var gutil = require('gulp-util')
var pkg = require('./package.json')
var devBuild = gutil.env.release ? '' : ' (dev build at ' + (new Date()).toUTCString() + ')'
var distHeader = '/*!\n\
* <%= pkg.name %> <%= pkg.version %><%= devBuild %> - <%= pkg.homepage %>\n\
* <%= pkg.license %> Licensed\n\
*/\n'
var jsSrcPaths = './src/**/*.js*'
var jsLibPaths = './lib/**/*.js'
gulp.task('clean-lib', function(cb) {
del(jsLibPaths, cb)
})
gulp.task('transpile-js', ['clean-lib'], function() {
return gulp.src(jsSrcPaths)
.pipe(plumber())
.pipe(react({harmony: true}))
.pipe(gulp.dest('./lib'))
})
gulp.task('lint-js', ['transpile-js'], function() {
return gulp.src(jsLibPaths)
.pipe(jshint('./.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
})
gulp.task('bundle-js', ['lint-js'], function() {
var b = browserify(pkg.main, {
debug: !!gutil.env.debug
, standalone: pkg.standalone
, detectGlobals: false
})
b.transform('browserify-shim')
var stream = b.bundle()
.pipe(source(pkg.name + '.js'))
.pipe(streamify(header(distHeader, {pkg: pkg, devBuild: devBuild})))
.pipe(gulp.dest('./dist'))
if (gutil.env.production) {
stream = stream
.pipe(rename(pkg.name + '.min.js'))
.pipe(streamify(uglify()))
.pipe(streamify(header(distHeader, {pkg: pkg, devBuild: devBuild})))
.pipe(gulp.dest('./dist'))
}
return stream
})
gulp.task('watch', function() {
gulp.watch(jsSrcPaths, ['bundle-js'])
})
gulp.task('default', ['bundle-js', 'watch'])