-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
142 lines (125 loc) · 3.78 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
/* Load plugins */
var gulp = require('gulp'),
sass = require('gulp-sass'),
watch = require('gulp-watch'),
jshint = require('gulp-jshint'),
notify = require('gulp-notify'),
uncss = require('gulp-uncss'),
connect = require('gulp-connect'),
nano = require('gulp-cssnano'),
concat = require('gulp-concat'),
imagemin = require('gulp-imagemin'),
uglify = require('gulp-uglify'),
pump = require('pump'),
open = require('gulp-open'),
sourcemaps = require('gulp-sourcemaps');
//-----------------------
// tasks for local servers with gulp-connect and gulp-open ----------------------------------
//-----------------------
gulp.task('connectBuild', function() {
connect.server({
root: 'build',
port: 8000,
livereload: true
});
});
gulp.task('connectDist', function() {
connect.server({
root: 'dist',
port: 8001
});
});
gulp.task('open-build', function() {
gulp.src(__filename)
.pipe(open({
uri: 'http://localhost:8000/'
}))
});
gulp.task('open-dist', ['uncss'], function() {
gulp.src(__filename)
.pipe(open({
uri: 'http://localhost:8001/'
}))
});
//-----------------------
// tasks for building process ----------------------------------
//-----------------------
gulp.task('css', function() {
return gulp.src('./src/sass/*.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./build/css'))
.pipe(connect.reload())
.pipe(notify('CSS task complete!'))
});
gulp.task('js', function() {
return gulp.src('./src/js/*.js')
.pipe(concat('main.js'))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(gulp.dest('./build/js'))
.pipe(connect.reload())
.pipe(notify('JS task complete!'))
});
gulp.task('html', function() {
return gulp.src('./src/*.html')
.pipe(gulp.dest('./build'))
.pipe(connect.reload())
.pipe(notify('site reloaded!'))
});
gulp.task('images', function() {
return gulp.src('./src/img/**')
.pipe(gulp.dest('./build/img'))
.pipe(connect.reload())
});
//-----------------------
// tasks for final deployment ----------------------------------
//-----------------------
gulp.task('html-dist', function() {
return gulp.src('./src/*.html')
.pipe(gulp.dest('./dist'))
});
gulp.task('js-dist', function(cb) { // gulp-uglify and "pump" as the example on npm
pump([
gulp.src('./build/js/*.js'),
uglify(),
gulp.dest('./dist/js')
],
cb
);
});
gulp.task('images-dist', function() {
return gulp.src('./build/img/**')
.pipe(imagemin())
.pipe(gulp.dest('./dist/img'))
});
gulp.task('uncss', function() {
return gulp.src('./build/css/*.css')
.pipe(notify('uncss is working...'))
.pipe(uncss({
html: ['http://localhost:8001/index.html']
}))
.pipe(nano())
.pipe(gulp.dest('./dist/css'))
.pipe(notify('READY FOR ONLINE DISTRIBUITION'))
});
/* Build task */
gulp.task('build', ['connectBuild', 'open-build', 'watch'], function() {
gulp.start('css', 'js', 'html', 'images');
});
/* Deploy task */
gulp.task('deploy', ['connectDist'], function() {
gulp.start('uncss', 'js-dist', 'html-dist', 'images-dist', 'open-dist');
});
/* Watch task */
gulp.task('watch', function() {
gulp.watch('./src/sass/**/*.scss', ['css']);
gulp.watch('./src/js/*.js', ['js']);
gulp.watch('./src/*.html', ['html']);
gulp.watch('./src/img/**', ['images']);
});
//-----------------------
// Default task (same as calling build) ----------------------------------
//-----------------------
gulp.task('default', ['build']);