-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
70 lines (60 loc) · 1.86 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 gulp = require('gulp');
var sass = require('gulp-ruby-sass')
var browserify = require('gulp-browserify');
var concat = require('gulp-concat');
var imagemin = require('gulp-imagemin');
var clean = require('gulp-clean');
var plumber = require('gulp-plumber');
var express = require('express');
var livereload = require('connect-livereload');
gulp.task('clean', function () {
return gulp.src('dist', { read: false })
.pipe(clean());
});
gulp.task('js', function () {
gulp.src('src/js/main.js')
.pipe(plumber())
.pipe(browserify({debug: true, extensions: ['.jsx'], transform: 'reactify'}))
.pipe(concat('main.js'))
.pipe(gulp.dest('dist/js'));
});
gulp.task('sass', function () {
gulp.src('src/css/*.scss')
.pipe(plumber())
.pipe(sass({sourcemap: true, sourcemapPath: '.', compass: true}))
.pipe(gulp.dest('dist/css'));
});
gulp.task('copy', function () {
gulp.src('src/*.html')
.pipe(gulp.dest('dist'));
gulp.src('src/images/**/*.*')
.pipe(gulp.dest('dist/images'));
});
gulp.task('express', function () {
var app = express();
app.use(livereload({port: 35729}));
app.use(express.static(__dirname + '/dist'));
app.get(/^[^?#]*/, function (req, res) {
res.sendFile(__dirname + '/dist/index.html');
});
app.listen(4000);
});
var tinylr;
gulp.task('livereload', function () {
tinylr = require('tiny-lr')();
tinylr.listen(35729);
});
function notifyLiveReload(event) {
var fileName = require('path').relative(__dirname, event.path);
tinylr && tinylr.changed({
body: {
files: [fileName]
}
});
}
gulp.task('default', ['js', 'sass', 'copy']);
gulp.task('server', ['default', 'express', 'livereload', 'watch']);
gulp.task('watch', function () {
gulp.watch('src/**/*.*', ['default']);
gulp.watch('dist/**/*.*', notifyLiveReload);
});