-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
66 lines (60 loc) · 2.11 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var gulpif = require('gulp-if');
var argv = require('yargs').argv;
var browserify = require('browserify');
var babelify = require('babelify');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
var autoprefixer = require('gulp-autoprefixer');
var less = require('gulp-less');
var csso = require('gulp-csso');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var plumber = require('gulp-plumber');
gulp.task('less', function() {
return gulp.src('public/css/main.less')
.pipe(plumber())
.pipe(less())
.pipe(autoprefixer())
.pipe(gulpif(argv.production, csso()))
.pipe(gulp.dest('public/css'));
});
gulp.task('react', function() {
return browserify({ entries: 'app/main.js', debug: true })
.transform('babelify', { presets: ['es2015', 'react'] })
.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(gulpif(argv.production, uglify()))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('public/js'));
});
gulp.task('watchify', function() {
var bundler = watchify(browserify({ entries: 'app/main.js', debug: true }, watchify.args));
bundler.transform('babelify', { presets: ['es2015', 'react'] });
bundler.on('update', rebundle);
return rebundle();
function rebundle() {
var start = Date.now();
return bundler.bundle()
.on('error', function(err) {
gutil.log(gutil.colors.red(err.toString()));
})
.on('end', function() {
gutil.log(gutil.colors.green('Finished rebundling in', (Date.now() - start) + 'ms'));
})
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('public/js'));
}
});
gulp.task('watch', function() {
gulp.watch('public/css/**/*.less', ['less']);
});
gulp.task('build', ['less', 'react']);
gulp.task('default', ['build', 'watch', 'watchify']);