-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpfile.js
89 lines (79 loc) · 2.2 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
var gulp = require('gulp')
var source = require('vinyl-source-stream')
var browserify = require('browserify')
var uglify = require('gulp-uglify')
var connect = require('gulp-connect')
var rename = require('gulp-rename')
var sass = require('gulp-sass')
var ghPages = require('gulp-gh-pages')
var jsonminify = require('gulp-jsonminify')
gulp.task('connect', function () {
connect.server({
root: 'build',
port: process.env.port || 8000,
livereload: true
})
})
gulp.task('browserify', function () {
return browserify('js/index.js')
.transform('babelify')
.bundle()
.on('error', function (err) {
console.error(err)
this.emit('end')
})
.pipe(source('js/app.js'))
.pipe(rename('app.js'))
.pipe(gulp.dest('build'))
})
gulp.task('sass', function () {
return gulp.src('./css/app.scss')
.pipe(sass({
outputStyle: 'compressed',
includePaths: [ './node_modules/basscss-sass' ]
}))
.on('error', sass.logError)
.pipe(rename('app.css'))
.pipe(gulp.dest('build'))
})
gulp.task('html', function () {
return gulp.src('./html/index.html', { base: './html' })
.pipe(gulp.dest('build'))
})
gulp.task('minify-json', function () {
return gulp.src('./html/*.json', { base: './html' })
.pipe(jsonminify())
.pipe(gulp.dest('build'))
})
gulp.task('reload', function () {
return gulp.src('./build/**/*')
.pipe(connect.reload())
})
gulp.task('uglify', ['browserify'], function () {
return gulp.src('build/app.js')
.pipe(uglify())
.pipe(rename('app.js'))
.pipe(gulp.dest('build'))
})
gulp.task('deploy', ['build', 'uglify'], function () {
return gulp.src('./build/**')
.pipe(ghPages())
})
gulp.task('watch', function () {
gulp.watch(['js/**/*.js', 'js/**/*.jsx'], function () {
gulp.start('browserify')
})
gulp.watch(['css/**/*.scss'], function () {
gulp.start('sass')
})
gulp.watch([ 'html/**/*.html' ], function () {
gulp.start('html')
})
gulp.watch([ 'html/**/*.json' ], function () {
gulp.start('minify-json')
})
gulp.watch([ 'build/**' ], ['reload'])
})
gulp.task('build', ['browserify', 'sass', 'html', 'minify-json'])
gulp.task('dev', ['build', 'connect', 'watch'])
gulp.task('default', ['serve'])