forked from cryptag/leapchat
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
163 lines (132 loc) · 4.3 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
const gulp = require('gulp'),
sass = require('gulp-sass'),
browserify = require('browserify'),
babelify = require('babelify'),
uglify = require('gulp-uglify'),
fs = require('fs'),
gutil = require('gulp-util'),
concat = require('gulp-concat'),
source = require('vinyl-source-stream'),
rev = require('gulp-rev'),
clean = require('gulp-clean'),
cleanCSS = require('gulp-clean-css'),
runSequence = require('run-sequence');
gulp.task('default', ['sass:watch']);
gulp.task('copy-index', function () {
gulp.src('./index.html')
.pipe(gulp.dest('./build/'));
});
// entry point for CSS build task sequence
gulp.task('build-css', function(){
runSequence('copy-index', 'reset-css', 'sass', 'concat-css', 'minify-css', 'clean-css', 'inject-css');
})
// wipe all CSS files from /build
gulp.task('reset-css', function(){
return gulp.src('build/*.css')
.pipe(clean());
});
// remove app CSS from /build
gulp.task('clean-css', function(){
return gulp.src('build/app.css')
.pipe(clean());
});
// compile all SASS in static/sass main.scss into CSS
gulp.task('sass', function () {
return gulp.src('./static/sass/main.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./static/css'));
});
gulp.task('sass:watch', function () {
gulp.watch('./static/sass/**/*.scss', ['sass', 'inject']);
});
// concat all CSS files (including bower includes) into single file
gulp.task('concat-css', function(){
var json = JSON.parse(fs.readFileSync('./static/assets.json'));
return gulp.src(json['stylesheets'])
.pipe(concat('app.css'))
.pipe(gulp.dest('./build'));
});
// compress and versionize single CSS file from concat
gulp.task('minify-css', function(){
return gulp.src('./build/app.css')
.pipe(cleanCSS())
.pipe(rev())
.pipe(gulp.dest('build'));
});
// inject compressed, versioned CSS file into index.html
gulp.task('inject-css', function(){
var inject = require('gulp-inject');
var injectSrc = gulp.src(['./build/*.css'], {read: false});
return gulp.src('./build/index.html')
.pipe(inject(injectSrc))
.pipe(gulp.dest('./build'));
});
// entry point for JS build task sequence
gulp.task('build-js', function(){
runSequence('reset-js', 'clean-js', 'browserify', 'concat-js', 'clean-js', 'inject-js');
});
// remove versioned production build from /build
gulp.task('reset-js', function(){
return gulp.src('build/*.min.js')
.pipe(clean());
});
// remove browserified app JS file from /build
gulp.task('clean-js', function(){
return gulp.src('build/app.js')
.pipe(clean());
});
// take React / ES6 app code and compile
// to browser-friendly version in /build
gulp.task('browserify', function(){
return browserify('./src/index.js')
.transform(babelify, {
presets: ['es2015', 'react'],
sourceMaps: true
})
.bundle()
.on('error', function (err) {
gutil.log(err.toString());
this.emit('end');
})
.pipe(source('app.js'))
.pipe(gulp.dest('./build'));
});
// take all listed JS dependencies and concat into single, versioned
// production build in /build
gulp.task('concat-js', function(){
var json = JSON.parse(fs.readFileSync('./static/assets.json'));
return gulp.src(json['scripts'])
.pipe(uglify())
.on('error', function(err){
gutil.log(err.toString());
})
.pipe(concat('build.min.js'))
.pipe(rev())
.pipe(gulp.dest('./build'));
});
// inject reference to production JS build into index.html
gulp.task('inject-js', function(){
var inject = require('gulp-inject');
var injectSrc = gulp.src(['./build/*.min.js'], {read: false});
return gulp.src('./build/index.html')
.pipe(inject(injectSrc))
.pipe(gulp.dest('./build'));
});
// development injection of static assets
gulp.task('inject', function(){
var wiredep = require('wiredep').stream;
var inject = require('gulp-inject');
var injectSrc = gulp.src(['./static/css/*.css',
'./static/js/*.js'], {read: false});
var injectOptions = {
ignorePath: '/static'
};
var options = {
bowerJson: require('./bower.json'),
directory: './static/lib'
};
return gulp.src('./index.html')
.pipe(wiredep(options))
.pipe(inject(injectSrc, injectOptions))
.pipe(gulp.dest('./'));
});