-
Notifications
You must be signed in to change notification settings - Fork 30
/
Gulpfile.js
156 lines (136 loc) · 4.86 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
// == Gulp Require Modules == //
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
cssmin = require('gulp-cssmin'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
livereload = require('gulp-livereload'),
plumber = require('gulp-plumber'),
imagemin = require('gulp-imagemin'),
pngcrush = require('imagemin-pngcrush'),
mainBowerFiles = require('main-bower-files'),
filter = require('gulp-filter'),
clean = require('gulp-clean');
// == Clean Tasks == //
gulp.task('clean-tmp', function(){
return gulp.src('dist/tmp/', {read: false})
.pipe(clean());
});
gulp.task('clean-scripts', function(){
return gulp.src('dist/js/*.js', {read: false})
.pipe(clean());
});
gulp.task('clean-styles', function(){
return gulp.src('dist/css/*.css', {read: false})
.pipe(clean());
});
gulp.task('clean-images', function(){
return gulp.src('dist/img/*', {read: false})
.pipe(clean());
});
// == STYLES TASKS == //
// = Only compiles SASS and autoprefixes = //
gulp.task('styles-dev', function() {
return gulp.src('src/sass/*.scss')
.pipe(plumber())
.pipe(sass({ style: 'expanded' }))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'))
.pipe(gulp.dest('dist/css/'));
});
// = Compiles SASS, autoprefixes then minifies the final version = //
gulp.task('styles-build', function() {
return gulp.src('src/sass/*.scss')
.pipe(plumber())
.pipe(sass({ style: 'expanded' }))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'))
.pipe(gulp.dest('dist/css/'))
.pipe(cssmin())
.pipe(gulp.dest('dist/css/'));
});
// == SCRIPTS TASKS == //
// = Only copies over the javascript files and concatinates them = //
gulp.task('scripts-dev',function(){
return gulp.src('src/js/*.js')
.pipe(plumber())
.pipe(concat('main.js'))
.pipe(gulp.dest('dist/js/'));
});
// = Uglifies the javascript files then concatinates them = //
gulp.task('scripts-build', function() {
return gulp.src('src/js/**/*.js')
.pipe(plumber())
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(gulp.dest('dist/js/'));
});
// == VENDOR TASKS == //
// = Copies and concatinates the development vendor CSS and JS specified in Bower (Read the Docs) = //
gulp.task('vendor-dev', function(){
gulp.src(mainBowerFiles())
.pipe(plumber())
.pipe(filter('*.js'))
.pipe(gulp.dest('dist/tmp/'))
.pipe(concat('vendor.js'))
.pipe(gulp.dest('dist/js/'));
gulp.src(mainBowerFiles())
.pipe(plumber())
.pipe(filter('*.css'))
.pipe(gulp.dest('dist/tmp/'))
.pipe(concat('vendor.css'))
.pipe(gulp.dest('dist/css/'));
});
// = Same thing as vendor-dev except we'll uglify the Javascript and cssmin the CSS = //
gulp.task('vendor-build', function() {
gulp.src(mainBowerFiles())
.pipe(plumber())
.pipe(filter('*.js'))
.pipe(gulp.dest('dist/tmp/'))
.pipe(uglify())
.pipe(concat('vendor.js'))
.pipe(gulp.dest('dist/js/'));
gulp.src(mainBowerFiles())
.pipe(plumber())
.pipe(filter('*.css'))
.pipe(gulp.dest('dist/tmp/'))
.pipe(cssmin())
.pipe(concat('vendor.css'))
.pipe(gulp.dest('dist/css/'));
});
// == IMAGE TASKS == //
// = Any images in the src/img folder are minified then copied over to the dist/img folder = //
gulp.task('imagemin', function () {
return gulp.src('src/img/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngcrush()]
}))
.pipe(gulp.dest('dist/img/'));
});
// == WATCH TASKS == //
// = Watches all SASS, JS, and the image folder for any changes, then runs the appropriate task.
// = Also watches all PHP, CSS, JS and the image folder in the dist folder for any changes then triggers livereload
gulp.task('watch', function() {
gulp.watch('src/sass/**/*.scss', ['styles-dev']);
gulp.watch('src/js/**/*.js', ['scripts-dev']);
gulp.watch('src/img/**', ['imagemin']);
livereload.listen();
gulp.watch('**/*.php').on('change', livereload.changed);
gulp.watch('dist/css/*.css').on('change', livereload.changed);
gulp.watch('dist/js/*.js').on('change', livereload.changed);
gulp.watch('dist/img/**').on('change', livereload.changed);
});
// == GULP TASKS == //
// = Clean Task = //
gulp.task('clean', ['clean-styles', 'clean-scripts']);
// = Development Task = //
gulp.task('dev', ['clean', 'vendor-dev', 'styles-dev', 'scripts-dev']);
// = Build Task = //
gulp.task('build', ['clean', 'vendor-build', 'styles-build', 'scripts-build']);
// = Image Task = //
gulp.task('image', ['imagemin']);
gulp.task('image-clear', ['clean-images', 'imagemin']);
// = Default Task = //
gulp.task('default', ['dev', 'watch']);