-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
98 lines (81 loc) · 2.17 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
'use strict';
var PORT = process.env.PORT || 3000;
var EXAMPLES_DIR = './examples';
var BUILD_DIR = 'dist';
var _ = require('lodash');
var babelify = require('babelify');
var browserify = require('browserify');
var browserSync = require('browser-sync');
var del = require('del');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var stylus = require('gulp-stylus');
var util = require('gulp-util');
var nib = require('nib');
var jeet = require('jeet');
var historyAPIFallback = require('connect-history-api-fallback');
function onError(error) {
util.log(error.message);
/*jshint validthis:true*/
this.emit('end');
}
gulp.task('browser-sync', function() {
return browserSync({
browser: [],
port: PORT,
server: {
baseDir: './' + BUILD_DIR,
middleware: [historyAPIFallback]
}
});
});
gulp.task('js', function() {
var bundler = watchify(browserify(EXAMPLES_DIR + '/js/index.jsx',
_.assign({
debug: true,
extensions: ['.jsx']
}, watchify.args)));
bundler.transform(babelify);
function rebundle() {
return bundler.bundle()
.on('error', onError)
.pipe(source('bundle.js'))
.pipe(gulp.dest(BUILD_DIR))
.pipe(browserSync.reload({stream: true, once: true}));
}
bundler
.on('log', util.log)
.on('update', rebundle);
return rebundle();
});
gulp.task('stylus', function() {
return gulp.src(EXAMPLES_DIR + '/css/index.styl')
.pipe(sourcemaps.init())
.pipe(stylus({
use: [
nib(),
jeet()
]
}))
.on('error', onError)
.pipe(sourcemaps.write())
.pipe(gulp.dest(BUILD_DIR))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('assets', function() {
return gulp.src(EXAMPLES_DIR + '/assets/**/*')
.pipe(gulp.dest(BUILD_DIR))
.pipe(browserSync.reload({stream: true, once: true}));
});
gulp.task('clean', del.bind(null, [BUILD_DIR]));
gulp.task('default', [
'assets',
'stylus',
'js',
'browser-sync'
], function() {
gulp.watch([EXAMPLES_DIR + '/css/**/*.styl'], ['stylus']);
gulp.watch([EXAMPLES_DIR + '/assets/**/*'], ['assets']);
});