-
Notifications
You must be signed in to change notification settings - Fork 57
/
gulpfile.js
165 lines (144 loc) · 4.19 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
'use strict';
var gulp = require('gulp'),
nodemon = require('gulp-nodemon'),
browserify = require('browserify'),
watchify = require('watchify'),
babelify = require('babelify'),
browserSync = require('browser-sync').create(),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
sass = require('gulp-sass'),
minifyCss = require('gulp-minify-css'),
gulpFilter = require('gulp-filter'),
mainBowerFiles = require('main-bower-files'),
RevAll = require('gulp-rev-all'),
revdel = require('gulp-rev-delete-original'),
runSequence = require('run-sequence'),
lrload = require('livereactload'),
shell = require('gulp-shell');
gulp.task('nodemon', ['bundle-css', 'bower', 'icons', 'watch-css', 'watchify', 'browser-sync'], function(){
runSequence('revision', function(){
nodemon({
script: 'app.js',
ext: 'js html json',
execMap: {
js: "node --harmony"
}
}).on('restart');
});
});
gulp.task('browser-sync', function(){
browserSync.init({
proxy: 'localhost:3333',
port: '3001',
open: false
});
});
gulp.task('production:push', function(){
runSequence('precompile:assets', 'revision', 'git:push', 'heroku:push', function(){
console.log('production push complete');
});
});
gulp.task('precompile:assets', ['bundle-css', 'bower', 'icons',
'browserify:production']);
gulp.task('git:push', shell.task([
"git add -A",
"git commit -m 'precompile for production'",
"git push"
]));
gulp.task('heroku:push', shell.task([
"git push heroku master"
]));
gulp.task('bundle-css', function(){
return gulp.src('./assets/css/*.scss')
.pipe(sass({
style: 'compressed',
includePaths: [
'./bower_components/bootstrap-sass/assets/stylesheets'
]
}).on('error', sass.logError))
.pipe(concat('bundle.css'))
.pipe(gulp.dest('public/css'))
.pipe(browserSync.stream())
.pipe(rename('bundle.min.css'))
.pipe(minifyCss())
.pipe(gulp.dest('public/css'));
});
gulp.task('bower', function(){
return gulp.src(mainBowerFiles())
.pipe(gulpFilter('*.js'))
.pipe (concat("vendor.js"))
.pipe(gulp.dest('./public/js'))
.pipe (rename("vendor.min.js"))
.pipe(uglify())
.pipe(gulp.dest('./public/js'));
});
gulp.task('icons', function() {
return gulp.src('./bower_components/bootstrap-sass/assets/fonts/bootstrap/**.*')
.pipe(gulp.dest('./public/fonts/bootstrap'));
});
gulp.task('watch-css', function () {
return gulp.watch('./assets/css/*.scss', ['bundle-css']);
});
gulp.task('browserify', function() {
const b = getBrowserifyInstance('dev');
b.transform(babelify);
return bundleBrowserify(b);
});
gulp.task('browserify:production', function() {
const b = getBrowserifyInstance('production');
b.transform(babelify);
return bundleBrowserify(b);
});
gulp.task('watchify', function(){
var b = getBrowserifyInstance();
var w = watchify(b);
w.transform(babelify, {});
w.on('update', function(){
console.log('updating bundle');
bundleBrowserify(w);
});
return bundleBrowserify(w);
});
gulp.task('revision', function(){
var revAll = new RevAll({
dontRenameFile: ['.jade']
});
gulp.src(['public/css/*.min.css', 'public/js/*.min.js', 'public/*.jade'], {base: 'public/'})
.pipe(revAll.revision())
.pipe(gulp.dest('public'))
.pipe(revdel())
});
var getBrowserifyInstance = function(env) {
var b = browserify('assets/js/app.jsx', {
debug: true,
extensions: ['.jsx'],
// live reload
plugin: (env === 'production') ? [] : [lrload],
// watchify arguments
cache: {},
packageCache: {},
fullPaths: false
});
return b;
}
var bundleBrowserify = function(b){
return b
.bundle(function(err){
if(err){
console.log(err.message);
} else {
console.log('bundle done');
}
})
.pipe(source('bundle.js'))
.pipe(gulp.dest('public/js'))
.pipe(rename('bundle.min.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('public/js'));
}
gulp.task('default', ['nodemon']);