forked from echenley/react-news
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
130 lines (107 loc) · 3.15 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
'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 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('src/styles/**/*')
.pipe($.plumber({
errorHandler: onError
}))
.pipe($.concat('main.scss'))
.pipe($.rubySass({
style: 'compressed',
precision: 10,
loadPath: ['src/bower_components']
}))
.pipe($.autoprefixer('last 3 versions'))
.pipe(gulp.dest('dist/styles'))
.pipe($.size());
});
// Scripts
gulp.task('scripts', function() {
var bundler;
bundler = browserify({
basedir: __dirname,
noparse: ['react/addons', 'reflux', 'fastclick', 'react-router'],
entries: ['./src/scripts/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('app.js'))
.pipe(prod ? $.streamify($.uglify()) : $.util.noop())
.pipe(gulp.dest('dist/scripts'))
.pipe($.notify(function() {
console.log('Bundling Complete - ' + (Date.now() - start) + 'ms');
}));
}
bundler.on('update', rebundle);
return rebundle();
});
// HTML
gulp.task('html', function() {
return gulp.src('src/*.html')
.pipe($.useref())
.pipe(gulp.dest('dist'))
.pipe($.size());
});
// Images
gulp.task('images', function() {
return gulp.src('src/images/**/*')
.pipe($.cache($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('dist/images'))
.pipe($.size());
});
// Webserver
gulp.task('serve', function() {
gulp.src('dist')
.pipe($.webserver({
livereload: true,
port: 9000,
fallback: 'index.html'
}));
});
// Clean
gulp.task('clean', function(cb) {
del(['dist/styles', 'dist/scripts', 'dist/images'], cb);
});
// Default task
gulp.task('default', ['clean', 'html', 'styles', 'scripts']);
// Watch
gulp.task('watch', ['html', 'styles', 'scripts', 'serve'], function() {
gulp.watch('src/*.html', ['html']);
gulp.watch('src/styles/**/*.scss', ['styles']);
gulp.watch('src/images/**/*', ['images']);
});