-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgulpfile.js
77 lines (68 loc) · 2.12 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
'use strict';
var gulp = require('gulp');
var util = require('gulp-util');
var browserSync = require('browser-sync');
var browserify = require('browserify');
var reactify = require('reactify');
var watchify = require('watchify');
var babelify = require('babelify');
var uglify = require('gulp-uglify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
gulp.task('html', function() {
gulp.src('./app/index.html')
.pipe(gulp.dest('./dist/'));
});
gulp.task('css', function () {
return gulp.src([
'node_modules/normalize.css/normalize.css',
'app/css/main.scss'
])
.pipe(concat('main.css'))
.pipe(sass({
precision: 10
}).on('error', sass.logError))
.pipe(gulp.dest('dist/css'));
});
gulp.task('js', function() {
browserify({
entries: './app/js/main.jsx',
debug: false
})
.transform([reactify, babelify])
.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('./dist/js/'));
});
gulp.task('watch-js', function () {
var bundler = watchify(browserify('./app/js/main.jsx', watchify.args))
.on('update', function () { util.log('Rebundling...'); })
.on('time', function (time) {
util.log('Rebundled in:', util.colors.cyan(time + 'ms'));
});
bundler.transform(reactify);
bundler.on('update', rebundle);
function rebundle() {
return bundler.bundle()
.on('error', function (err) {
util.log(err);
})
.pipe(source('bundle.js'))
.pipe(gulp.dest('./dist/js'))
.pipe(browserSync.reload({ stream: true }));
}
return rebundle();
});
gulp.task('serve', ['css', 'html', 'watch-js'], function() {
browserSync({
server: ['./dist']
});
gulp.watch(['app/index.html'], ['html', browserSync.reload]);
gulp.watch(['app/css/**/*'], ['css', browserSync.reload]);
});
gulp.task('build', ['html', 'css', 'js']);
gulp.task('default', ['serve']);