-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
135 lines (109 loc) · 3.44 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
var gulp = require('gulp'),
minifyCss = require('gulp-minify-css'),
concatCss = require('gulp-concat-css'),
rev = require('gulp-rev'),
htmlReplace = require('gulp-html-replace'),
revReplace = require('gulp-rev-replace'),
htmlMin = require('gulp-htmlmin'),
path = require('path'),
revNapkin = require('gulp-rev-napkin'),
del = require('del'),
server = require('gulp-server-livereload'),
filenames = require('gulp-filenames'),
shell = require('gulp-shell'),
symlink = require('gulp-symlink'),
runSequence = require('run-sequence'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
gutil = require('gulp-util'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
browserify = require('browserify');
gulp.task('default', function(callback) {
runSequence('clean:before',
['bundle',
'watch',
'serve'],
callback);
});
gulp.task('bundle', function(callback) {
runSequence('clean:before',
['compile', 'minify-css'],
['revision', 'static'],
'bundle-process-html',
'clean:after', callback);
});
gulp.task('clean:before', function(callback) {
del('dist/*', callback);
});
gulp.task('clean:after', function(callback) {
del('rev-manifest.json', callback);
});
gulp.task('minify-css', function() {
return gulp.src(['src/css/reset.css', 'src/css/base.css', 'src/**/*.css']).
pipe(concatCss('style.css', {
rebaseUrls: false
})).
pipe(minifyCss()).
pipe(gulp.dest('dist'));
});
gulp.task('revision', function() {
return gulp.src(['dist/script.js', 'dist/style.css']).
pipe(rev()).
pipe(gulp.dest('dist')).
pipe(revNapkin()).
pipe(rev.manifest()).
pipe(gulp.dest(''));
});
gulp.task('static', function() {
return gulp.src('static/**/*').
pipe(gulp.dest('dist/static'));
});
gulp.task('get-css', function() {
return gulp.src(['src/**/reset.css', 'src/**/base.css', 'src/**/*.css']).
pipe(filenames('css'));
});
gulp.task('bundle-process-html', function() {
var manifest = gulp.src('./rev-manifest.json');
return gulp.src('src/index.html').
pipe(htmlReplace({
'vchat': ['style.css', 'script.js']
})).
pipe(gulp.dest('dist')).
pipe(revReplace({manifest: manifest})).
pipe(htmlMin({collapseWhitespace: true})).
pipe(gulp.dest('dist'));
});
gulp.task('watch', function() {
function changeLogger(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
}
gulp.watch('src/**/*.js').on('change', changeLogger);
gulp.watch('src/index.html', ['bundle']).on('change', changeLogger);
});
gulp.task('serve', function() {
return gulp.src('dist').pipe(server({
watchPath: 'src',
port: 1971,
livereload: {
enable: true,
path: 'src'
},
open: true
}));
});
gulp.task('compile', function () {
// set up the browserify instance on a task basis
var b = browserify({
entries: ['./src/app.js'],
debug: true
});
return b.bundle()
.pipe(source('./src/app.js'))
.pipe(buffer())
// Add transformation tasks to the pipeline here.
.pipe(uglify())
.on('error', gutil.log)
.pipe(rename('script.js'))
.pipe(gulp.dest('./dist/'));
});