-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
173 lines (144 loc) · 4.4 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
'use strict';
var gulp = require('gulp');
var del = require('del');
var path = require('path');
var browserify = require('browserify');
var reactify = require('reactify');
var watchify = require('watchify');
var uglify = require('gulp-uglify');
var less = require('gulp-less');
var minifyCSS = require('gulp-minify-css');
var source = require('vinyl-source-stream');
var $ = require('gulp-load-plugins')();
var prod = $.util.env.prod;
// gulp-plumber for error handling
function onError() {
/* jshint ignore:start */
var args = Array.prototype.slice.call(arguments);
$.util.beep();
$.notify.onError({
title: "Compile Error",
message: "<%= error.message %>"
}).apply(this, args);
this.emit('end'); // Keep gulp from hanging on this task
/* jshint ignore:end */
}
// Styles
gulp.task('styles', function() {
return gulp.src('styles/movie-finder.less')
.pipe($.plumber({
errorHandler: onError
}))
.pipe(less({paths: [ path.join(__dirname, 'styles') ],
sourceMap:true,
sourceMapBasepath:__dirname,
sourceMapRootpath:'/'}))
.pipe($.autoprefixer('last 3 versions'))
.pipe(minifyCSS({keepBreaks:false}))
.pipe(gulp.dest('public/styles'))
.pipe($.size());
});
// Scripts
gulp.task('scripts', ['clean'], function() {
var bundler;
bundler = browserify({
basedir: __dirname,
noparse: ['react/addons', 'reflux', 'fastclick', 'react-router'],
entries: ['./src/app.jsx'],
transform: [reactify],
extensions: ['.jsx'],
debug: true,
cache: {},
packageCache: {},
fullPaths: true
});
bundler = watchify(bundler);
function rebundle() {
console.log('Bundling Scripts...');
var start = Date.now();
return bundler.bundle()
.on('error', onError)
.pipe(source('bundle.js'))
.pipe($.util.noop())
.pipe(gulp.dest('public/scripts'))
.pipe($.notify(function() {
console.log('Bundling Complete - ' + (Date.now() - start) + 'ms');
}));
}
bundler.on('update', rebundle);
return rebundle();
});
// Prod Scripts (no watchify)
gulp.task('prodscripts', ['clean'], function() {
var bundler;
bundler = browserify({
basedir: __dirname,
noparse: ['react/addons', 'reflux', 'fastclick', 'react-router'],
entries: ['./src/app.jsx'],
transform: [reactify],
extensions: ['.jsx'],
debug: true,
cache: {},
packageCache: {},
fullPaths: true
});
function rebundle() {
console.log('Bundling Scripts...');
var start = Date.now();
return bundler.bundle()
.on('error', onError)
.pipe(source('bundle.js'))
.pipe($.streamify($.uglify()))
.pipe(gulp.dest('public/scripts'))
.pipe($.notify(function() {
console.log('Bundling Complete - ' + (Date.now() - start) + 'ms');
}));
}
return rebundle();
});
// HTML
gulp.task('html', ['clean'], function() {
return gulp.src('src/*.html')
.pipe($.useref())
.pipe(gulp.dest('public'))
.pipe($.size());
});
// TXT
gulp.task('txt', ['clean'], function() {
return gulp.src('src/*.txt')
.pipe($.useref())
.pipe(gulp.dest('public'))
.pipe($.size());
});
// Images
gulp.task('images', ['clean'], function() {
return gulp.src('assests/images/**/*')
.pipe($.cache($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('public/images'))
.pipe($.size());
});
// Local Webserver
gulp.task('serve', function() {
gulp.src('public')
.pipe($.webserver({
livereload: true,
port: 4444,
fallback: 'index.html'
}));
});
// Clean
gulp.task('clean', function(cb) {
del(['public/*.*', 'public/styles', 'public/scripts', 'public/images'], cb);
});
// Default task
gulp.task('default', ['html', 'txt', 'styles', 'prodscripts', 'images']);
// Watch
gulp.task('watch', ['html', 'styles', 'scripts', 'images', 'serve'], function() {
gulp.watch('src/*.html', ['html']);
gulp.watch('styles/**/*.less', ['styles']);
gulp.watch('assests/images/**/*', ['images']);
});