forked from VladimirPal/react-flux-backbone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
112 lines (92 loc) · 2.25 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
105
106
107
108
109
110
111
112
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserify = require('browserify');
var del = require('del');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var _ = require('lodash');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var api = require('./api/api');
var handleErrors = function() {
var args = Array.prototype.slice.call(arguments);
delete args[0]['stream'];
$.util.log(args);
this.emit('end');
};
gulp.task('clean', function(cb) {
del([
'app/tmp'
], cb);
});
gulp.task('html', function() {
return gulp.src('./src/index.html')
.pipe($.plumber())
.pipe(gulp.dest('./dist'));
});
gulp.task('styles', function() {
return gulp.src('./src/styles/main.less')
.pipe($.less())
.pipe($.autoprefixer())
.pipe($.rename('bundle.css'))
.pipe(gulp.dest('./dist'))
.pipe(reload({ stream: true }));
});
var bundler = _.memoize(function(watch) {
var options = {debug: true};
if (watch) {
_.extend(options, watchify.args);
}
var b = browserify('./src/main.js', options);
if (watch) {
b = watchify(b);
}
return b;
});
function bundle(cb, watch) {
return bundler(watch).bundle()
.on('error', handleErrors)
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest('./dist'))
.on('end', cb)
.pipe(reload({ stream: true }));
}
gulp.task('scripts', function(cb) {
process.env.BROWSERIFYSWAP_ENV = 'dist';
bundle(cb, true);
});
gulp.task('fonts', function() {
var fonts = [
'./node_modules/font-awesome/fonts/*'
];
return gulp.src(fonts)
.pipe(gulp.dest('./dist/fonts'));
});
var reporter = 'spec';
gulp.task('build', [
'clean',
'html',
'fonts',
'styles',
'scripts'
]);
gulp.task('watch', ['build'], function(cb) {
browserSync({
server: {
baseDir: 'dist',
middleware: function(req, res, next) {
api(req, res, next);
}
}
});
reporter = 'dot';
bundler(true).on('update', function() {
gulp.start('scripts');
});
gulp.watch(['./src/main.less', './src/**/*.less'], ['styles']);
});
gulp.task('default', ['watch']);