-
Notifications
You must be signed in to change notification settings - Fork 24
/
gulpfile.js
104 lines (92 loc) · 2.41 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
96
97
98
99
100
101
102
103
104
var browserify = require('browserify');
var gulp = require('gulp');
var reactify = require('reactify');
var buffer = require('vinyl-buffer');
var cssmin = require('gulp-cssmin');
var ignore =require('gulp-ignore');
var less = require('gulp-less');
var livereload = require('gulp-livereload');
var notify = require('gulp-notify');
var shell = require('gulp-shell');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var watchify = require('watchify');
var runLess = function() {
return gulp
.src('./views/css/toureiro.less')
.pipe(less())
.pipe(gulp.dest('./public/dev/css'))
.pipe(livereload());
};
var runLessMin = function() {
return gulp
.src('./views/css/toureiro.less')
.pipe(less())
.pipe(cssmin())
.pipe(gulp.dest('./public/css'));
}
gulp.task('less', runLess);
gulp.task('lessMin', runLessMin);
gulp.task('buildBundle', function() {
var bundler = browserify({
entries: './views/jsx/index.jsx',
debug: true,
transform: [reactify]
});
return bundler.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify().on('error', gutil.log))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./public/js/'));
});
function watchBundle() {
var watcher = watchify(browserify({
entries: './views/jsx/index.jsx',
debug: true,
transform: [reactify],
cache: {},
packageCache: {},
fullPaths: true
}));
watcher.on('update', function() {
bundle(watcher);
});
watcher.on('log', gutil.log);
bundle(watcher);
}
function bundle(bundler) {
var start = Date.now();
console.log('Bundling...');
bundler
.bundle()
.on('error', gutil.log)
.pipe(source('app.js'))
.pipe(buffer())
.pipe(gulp.dest('./public/dev/js/'))
.pipe(livereload())
.pipe(notify(function() {
console.log('Bundled! Process took', (Date.now() - start) + 'ms');
}));
}
gulp.task('watchBundle', watchBundle);
gulp.task('watchLess', function() {
runLess();
gulp.watch('./views/css/**/*.less', ['less']);
});
gulp.task('watch', ['watchBundle', 'watchLess']);
gulp.task('livereload', function() {
livereload.listen();
});
gulp.task('server', shell.task([
'nodemon -w ./lib ./server.js'
]));
gulp.task('dev', [
'livereload',
'watch',
'server'
]);
gulp.task('build', ['buildBundle', 'lessMin']);