-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
123 lines (108 loc) · 3.14 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
'use strict'
var gulp = require('gulp'),
connect = require('gulp-connect'),
historyApiFallback = require('connect-history-api-fallback')(),
browserify = require('browserify'),
babelify = require('babelify'),
minifyHTML = require('gulp-minify-html'),
uglify = require('gulp-uglify'),
source = require('vinyl-source-stream'),
stylus = require('gulp-stylus'),
bower = require('gulp-bower'),
inject = require('gulp-inject'),
runSequence = require('gulp-run-sequence'),
clean = require('gulp-clean')
gulp.task('server', function() {
connect.server({
root: './build',
hostname: '0.0.0.0',
port: 3000,
livereload: true,
middleware: function(connect, opt) {
return [ historyApiFallback ];
}
});
});
gulp.task('reactjs', function() {
return browserify({
entries: './src/index.jsx',
extensions: ['.jsx'],
debug: true
})
.transform(babelify.configure({
compact: false
}))
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('./build/js'))
})
gulp.task('minifyHTML', function() {
var opts = {
conditionals: true,
spare:true
};
return gulp.src('./build/**/*.html')
.pipe(minifyHTML(opts))
.pipe(gulp.dest('./build/'))
.pipe(connect.reload())
})
gulp.task('uglify', function() {
return gulp.src('build/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('build/js'));
});
gulp.task('bower', function() {
return bower()
.pipe(gulp.dest('./src/bower_components'))
});
gulp.task('stylus', function () {
gulp.src('./src/stylus/**/*.styl')
.pipe(stylus({
compress: true
}))
.pipe(gulp.dest('./build/css'));
});
gulp.task('jquery',function() {
return gulp.src('./src/bower_components/jquery/dist/jquery.min.js')
.pipe(gulp.dest('./build/js/vendor'))
})
gulp.task('bootstrap',function() {
return gulp.src('./src/bower_components/bootstrap/dist/css/bootstrap.min.css')
.pipe(gulp.dest('./build/css/vendor'))
})
gulp.task('html',function() {
return gulp.src('./src/**/*.html')
.pipe(gulp.dest('./build'))
})
gulp.task('inject', function () {
var target = gulp.src('./build/**/*.html');
// It's not necessary to read the files (will speed up things),
// we're only after their paths:
var sources = gulp.src(['./build/**/*.js', './build/**/*.css'],
{ read: false })
return target.pipe(inject(sources,{ignorePath: 'build/'}))
.pipe(gulp.dest('./build'))
});
gulp.task('build', function() {
runSequence('build-clean', 'bower', ['stylus', 'reactjs', 'jquery',
'bootstrap', 'html'],'inject',['uglify', 'minifyHTML'], 'watch');
});
gulp.task('build-clean', function() {
return gulp.src('build').pipe(clean());
});
gulp.task('buildCSS', function(){
runSequence('stylus','buildHTML')
})
gulp.task('buildJS', function(){
runSequence('reactjs','uglify','buildHTML')
})
gulp.task('buildHTML', function(){
runSequence('html','inject','minifyHTML')
})
gulp.task('watch', function() {
gulp.watch('./src/**/*.styl', ['buildCSS'])
gulp.watch('./src/**/*.jsx', ['buildJS'])
gulp.watch('./src/**/*.html', ['buildHTML'])
gulp.watch('./bower.json', ['bower'])
})
gulp.task('default', ['build', 'server'])