-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
152 lines (140 loc) · 3.98 KB
/
gulpfile.js
File metadata and controls
152 lines (140 loc) · 3.98 KB
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
// Dependencies
var gulp = require('gulp'),
// CSS stuff
sass = require('gulp-sass'),
autoprefix = require('gulp-autoprefixer'),
minify = require('gulp-minify-css'),
// Javascript stuff
uglify = require('gulp-uglify'),
strip = require('gulp-strip-debug'),
concat = require('gulp-concat'),
// Images
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
// Other
clean = require('gulp-rimraf');
// Assets
var paths = {
assets: {
styles: {
dir: 'app/assets/styles',
files: 'app/assets/styles/**/*.scss'
},
scripts: {
dir: 'app/assets/scripts/',
files: [
'app/assets/scripts/src/**/*.js',
'app/assets/scripts/vendor/**/*.js',
'app/assets/scripts/main.js'
]
},
images: {
dir: 'app/assets/images',
files: 'app/assets/images/**/*'
}
},
public: {
styles: 'public/styles',
scripts: 'public/scripts',
images: 'public/images',
}
}
// General settings
var settings = {
autoprefix: {
versions: 'last 4 version'
}
}
/**
* Styles task
* -----------------
* Grabs everything inside the styles & sprites directories, concantinates
* and compiles scss, builds sprites, and then outputs them to their
* respective target directories.
*/
gulp.task('styles', function() {
gulp.src(paths.assets.styles.files)
.pipe(sass())
.pipe(autoprefix(settings.autoprefix.versions))
.pipe(gulp.dest(paths.public.styles));
});
/**
* Scripts task
* ------------
* Grabs everything inside the scripts directory, concantinates and minifies,
* and then outputs them to the target directory.
*/
gulp.task('scripts', function() {
gulp.src(paths.assets.scripts.files)
.pipe(concat('main.min.js'))
.pipe(gulp.dest(paths.public.scripts));
});
/**
* Image task
* ----------
* Grabs everything inside the images directory, optimises each image,
* and then outputs them to the target directory.
*/
gulp.task('images', function() {
gulp.src(paths.assets.images.files)
.pipe(cache(imagemin({optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest(paths.public.images));
});
/**
* Cache-buster task
* -----------------
* Completely clear the cache to stop image-min outputting oncorrect image names etc
*/
gulp.task('clear', function (done) {
return cache.clearAll(done);
});
/**
* Cleaner task
* ------------
* This simply deletes all of the main assets folders.
*/
gulp.task('clean', function() {
return gulp.src([paths.public.styles, paths.public.scripts, paths.public.images], {read: false})
.pipe(clean());
});
/**
* Watch task
* ----------
* Watches the different directores for changes and then
* runs their relevant tasks and livereloads.
*/
gulp.task('watch', function() {
// Run the appropriate task when assets change
gulp.watch(paths.assets.styles.files, ['styles']);
gulp.watch(paths.assets.scripts.files, ['scripts']);
gulp.watch(paths.assets.images.files, ['images']);
});
/**
* Deploy task
* -----------
* Runs all of the main tasks, plus minification.
*/
gulp.task('deploy', ['clean'], function() {
// Run the styles task, but minify the output
gulp.src(paths.assets.styles.files)
.pipe(sass())
.pipe(autoprefix(settings.autoprefix.versions))
.pipe(minify())
.pipe(gulp.dest(paths.public.styles));
// Run the JS task, but strip out debugging code and the uglify it
gulp.src(paths.assets.scripts.files)
.pipe(concat('main.min.js'))
.pipe(strip())
.pipe(uglify())
.pipe(gulp.dest(paths.public.scripts));
// Run the image task
gulp.start('images');
});
/**
* Defualt task
* ------------
* Runs every task, and then watches files for changes.
*/
gulp.task('default', ['clean'], function() {
gulp.start('styles', 'scripts', 'images', 'watch');
});