-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
120 lines (102 loc) · 3.02 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
113
114
115
116
117
118
119
120
var gulp = require('gulp');
var fs = require('fs');
var browserify = require('gulp-browserify');
var greact = require('gulp-react');
var sourcemaps = require('gulp-sourcemaps');
var less = require('gulp-less');
var prefixer = require('gulp-autoprefixer');
var gutil = require('gulp-util');
var plumber = require('gulp-plumber');
var refresh = require('gulp-livereload');
var lrserver = require('tiny-lr')();
var express = require('express');
var parse = require('csv-parse');
var livereload = require('connect-livereload');
var karma = require('karma').server;
var livereloadport = 35729;
var serverport = 4000;
var server = express();
//Add livereload middleware before static-middleware
server.use(livereload({
port: livereloadport
}));
//We only configure the server here and start it only when running the watch task
server.use(express.static(__dirname + '/public'));
/**
* Run test once and exit
*/
gulp.task('test', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done);
});
gulp.task('serve', function() {
//Set up your static fileserver, which serves files in the build dir
server.listen(serverport);
});
gulp.task('less', function() {
gulp
.src('./src/less/base.less')
.pipe(plumber(function(error) {
gutil.log(gutil.colors.red(error.message));
gutil.beep();
this.emit('end');
}))
.pipe(sourcemaps.init())
.pipe(less())
.pipe(prefixer('last 4 versions', 'ie 8'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./public/css'))
.pipe(refresh(lrserver));
});
gulp.task('less:build', function() {
gulp
.src('./src/less/base.less')
.pipe(plumber(function(error) {
gutil.log(gutil.colors.red(error.message));
gutil.beep();
this.emit('end');
}))
.pipe(sourcemaps.init())
.pipe(less())
.pipe(prefixer('last 4 versions', 'ie 8'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./public/css'));
});
gulp.task('less:watch', ['less'], function(){
gulp.watch('./src/less/**/*.less', ['less'])
});
gulp.task('jsx', function() {
return gulp.src('src/**/*.js')
.pipe(greact({harmony: true}))
.pipe(gulp.dest('build'));
});
gulp.task('scripts', ['jsx'], function() {
return gulp.src('build/main.js')
.pipe(sourcemaps.init())
.pipe(browserify({
}))
.pipe(gulp.dest('public/js'))
.pipe(sourcemaps.write())
.pipe(refresh(lrserver));
});
gulp.task('scripts:build', ['jsx'], function() {
return gulp.src('build/main.js')
.pipe(sourcemaps.init())
.pipe(browserify({
}))
.pipe(gulp.dest('public/js'))
.pipe(sourcemaps.write())
});
gulp.task('html:watch', function() {
gulp.watch('public/index.html', function() {
return gulp.src('public/index.html')
.pipe(refresh(lrserver));
});
});
gulp.task('scripts:watch', ['scripts'], function() {
gulp.watch('src/**/*.js', ['scripts']);
});
gulp.task('watch', ['scripts:watch', 'less:watch', 'html:watch', 'serve']);
gulp.task('default', ['scripts:build', 'less:build']);