-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgulpfile.js
95 lines (78 loc) · 2.2 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var browserify = require('browserify')
var gulp = require('gulp')
var gutil = require('gulp-util')
var jshint = require('gulp-jshint')
var nodemon = require('gulp-nodemon')
var plumber = require('gulp-plumber')
var react = require('gulp-react')
var source = require('vinyl-source-stream')
var streamify = require('gulp-streamify')
var uglify = require('gulp-uglify')
var jsSrcPaths = './src/**/*.js*'
var jsLibPaths = './lib/**/*.js'
var bundledDeps = [
'react',
'react-dom',
'react-router',
'react-router/lib/BrowserHistory',
'react-router/lib/experimental/AsyncProps',
'newforms',
'superagent-ls'
]
process.env.NODE_ENV = gutil.env.production ? 'production' : 'development'
process.env.HOST = '127.0.0.1'
process.env.PORT = '3000'
gulp.task('transpile-js', 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('./lib/client.js', {
debug: !!gutil.env.debug,
detectGlobals: false
})
bundledDeps.forEach(function(dep) { b.external(dep) })
b.transform('envify')
var stream = b.bundle()
.pipe(source('app.js'))
if (gutil.env.production) {
stream = stream.pipe(streamify(uglify()))
}
return stream.pipe(gulp.dest('./static/js'))
})
gulp.task('bundle-deps', function() {
var b = browserify({
debug: !!gutil.env.debug//,
//detectGlobals: false
})
bundledDeps.forEach(function(dep) { b.require(dep) })
b.transform('envify')
var stream = b.bundle()
.pipe(source('deps.js'))
if (gutil.env.production) {
stream = stream.pipe(streamify(uglify()))
}
return stream.pipe(gulp.dest('./static/js'))
})
gulp.task('bundle', ['bundle-deps', 'bundle-js'])
gulp.task('server', function(cb) {
nodemon({
script: './lib/server.js',
ignore: ['./src/*', './static/*'],
ext: 'jade js',
delay: 5//,
//nodeArgs: ['--debug']
})
cb()
})
gulp.task('watch', function() {
gulp.watch(jsSrcPaths, ['bundle-js'])
})
gulp.task('default', ['bundle-js', 'watch'])