-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
81 lines (67 loc) · 1.66 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
'use strict'
const browserify = require('browserify')
const gulp = require('gulp')
const source = require('vinyl-source-stream')
const uglify = require('gulp-uglify')
const buffer = require('vinyl-buffer')
const gutil = require('gulp-util')
const serve = require('gulp-serve')
const sass = require('gulp-sass')
const errorHandler = function (err) {
gutil.log('Error', gutil.colors.red(err))
gutil.beep()
}
const bundler = (options) => browserify(
Object.assign({
entries: ['client/main.js'],
debug: false,
transform: ['babelify'],
extensions: ['.jsx']
}, options)
)
const buildStyles = (entry) => {
return gulp.src(entry)
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./docs'))
}
const bundle = (bundler, outputSource) => {
bundler
.bundle()
.on('error', errorHandler)
.pipe(source('main.js'))
.pipe(gulp.dest('./docs'))
}
gulp.task('build', ['fonts', 'styles'], function () {
bundler()
.bundle()
.pipe(source('main.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('./docs'))
})
gulp.task('fonts', () => {
return gulp.src([
'node_modules/font-awesome/fonts/*'
])
.pipe(gulp.dest('./docs/fonts'))
})
gulp.task('styles', function () {
return buildStyles('./styles/main.scss')
})
gulp.task('styles:watch', ['styles'], function () {
return gulp.watch('./styles/*.scss', ['styles'])
})
gulp.task('watch', ['fonts', 'styles:watch'], () => {
const b = bundler({
plugin: ['watchify'],
cache: {},
packageCache: {}
})
b.on('update', () => bundle(b))
b.on('log', (log) => gutil.log(`main.js: ${log}`))
bundle(b)
})
gulp.task('serve', serve({
root: ['docs'],
port: 9090
}))