-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
144 lines (114 loc) · 3.25 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//Include gulp, and launch the task loader
var gulp = require('gulp');
var fs = require('fs-extra');
//Manage CLI flags
var args = require('yargs').argv;
//Get all the other modules necessary to build this out
var bourbon = require('node-bourbon');
var bowerMain = require('main-bower-files');
var browserify = require('gulp-browserify');
var concat = require('gulp-concat');
var csso = require('gulp-csso');
var debug = require('gulp-debug');
var jshint = require('gulp-jshint');
var react = require('gulp-react');
var replace = require('gulp-replace');
var sass = require('gulp-sass');
var watch = require('gulp-watch');
var uglify = require('gulp-uglify');
//Error handling
function handleError (err) {
console.log(err.toString());
//process.exit(-1);
this.emit('end');
}
//Process SCSS
gulp.task('sass', function(){
return gulp.src('./src/sass/style.scss')
.pipe(sass({
includePaths: bourbon.includePaths
})).on('error', handleError)
.pipe(gulp.dest('./src/bundle'))
});
//Lint the JS
gulp.task('lint', function () {
return gulp.src(['./src/js/**/*(*.jsx|*.js)'])
.pipe(jshint({
expr: true
})).on('error', handleError)
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
//Bundle and minify the libraries
gulp.task('libs', function(){
return gulp.src(bowerMain({}))
.pipe(concat('libs.js'))
.pipe(gulp.dest('./src/bundle'))
});
//Make a single JS bundle
gulp.task('bundle', ['lint'], function(){
return gulp.src('./src/js/app.js')
.pipe(browserify({
//debug: !args.dist,
file: 'app.js',
transform: ['reactify'],
extensions: ['.jsx'],
bundleExternal: args.dist,
external: args.dist ? false : [
'backbone',
'backbone-associations',
'marked',
'react',
'reqwest',
'underscore',
'velocity',
]
})).on('error', handleError)
.pipe(gulp.dest('./src/bundle'))
});
//Export JSON
gulp.task('dist-json', function(){
return gulp.src('./src/json/**')
.pipe(gulp.dest('./json/'))
});
//Minify the JS, and output to the "dist" folder
gulp.task('dist-js', ['libs', 'bundle'], function(){
return gulp.src('./src/bundle/**/*.js')
.pipe(uglify())
.pipe(gulp.dest('./dist/bundle'))
});
//Copy the fonts
gulp.task('dist-icons', function(){
return gulp.src('./src/icons/fonts/**')
.pipe(gulp.dest('./dist/bundle/icons'))
});
//Copy the images
gulp.task('dist-img', function(){
return gulp.src('./src/img/**')
.pipe(gulp.dest('./dist/img'))
});
//Minify the CSS, and output to the "dist" folder
gulp.task('dist-css', ['sass'], function(){
return gulp.src('./src/bundle/**/*.css')
.pipe(replace('../../icons/fonts/icomoon', './icons/icomoon'))
.pipe(csso())
.pipe(gulp.dest('./dist/bundle'))
});
//Minify the HTML, and output to the "dist" folder
gulp.task('dist', ['dist-img', 'dist-json', 'dist-js', 'dist-icons', 'dist-css'], function(){
return gulp.src('./src/index.html')
.pipe(gulp.dest('./dist'))
});
//Load gulp watchers
gulp.task('watch', function(){
var cssWatcher = watch('./src/sass/**/*(*.sass|*.scss)', function(){
gulp.start('sass', function(){
console.log('Style bundle updated');
});
});
var jsWatcher = gulp.watch('./src/*(js|json)/**/*(*.jsx|*.js|*.json)', function(){
gulp.start('bundle', function(){
console.log('Browserify bundle updated');
});
});
});