This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathgulpfile.js
66 lines (57 loc) · 1.8 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
'use strict';
// built in deps
var path = require('path');
// external modules
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var gulp = require('gulp');
var gutil = require('gulp-util');
var less = require('gulp-less');
var livereload = require('gulp-livereload');
var newer = require('gulp-newer');
var rename = require('gulp-rename');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var to5 = require('gulp-6to5');
var watchify = require('watchify');
gulp.task('server', function() {
return gulp.src('src/**/*.js')
.pipe(newer('bin'))
.pipe(to5())
.pipe(gulp.dest('bin'));
});
var bundler = watchify(browserify('./src/client.jsx', watchify.args));
// add any other browserify options or transforms here
bundler.transform('reactify', {'es6': true});
bundler.transform('6to5ify');
gulp.task('client', bundle); // so you can run `gulp js` to build the file
bundler.on('update', bundle); // on any dep update, runs the bundler
gulp.task('less', function() {
gulp.src('src/*.less')
.pipe(less())
.pipe(gulp.dest('bin'));
});
gulp.task('watch', function() {
livereload.listen();
gulp.watch(['src/**/*.js', 'src/**/*.jsx'], ['client']);
gulp.watch('src/**/*.js', ['server']);
gulp.watch('src/*.less', ['less']);
});
gulp.task('default', [
'client',
'server',
'less'
], function() {});
function bundle() {
return bundler.bundle()
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('bundle.js'))
// optional, remove if you dont want sourcemaps
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file
.pipe(sourcemaps.write('./')) // writes .map file
//
.pipe(gulp.dest('./bin'))
.pipe(livereload());
}