forked from digitalthrive/Harvest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
164 lines (146 loc) · 5.75 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
164
//initialize all of our variables
var app, base, concat, directory, gulp, gutil, hostname, path, refresh, sass, uglify, imagemin, cache, minifyCSS, del, connect, autoprefixer;
var autoPrefixBrowserList = ['last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'];
//load all of our dependencies
//add more here if you want to include more libraries
gulp = require('gulp');
gutil = require('gulp-util');
concat = require('gulp-concat');
uglify = require('gulp-uglify');
sass = require('gulp-sass');
imagemin = require('gulp-imagemin');
cache = require('gulp-cache');
minifyCSS = require('gulp-minify-css');
connect = require('gulp-connect');
del = require('del');
autoprefixer = require('gulp-autoprefixer');
gulp.task('connect', function() {
connect.server({
root: 'app',
livereload: true
});
});
//compressing images & handle SVG files
gulp.task('images', function(tmp) {
console.log(tmp);
gulp.src(['app/images/*.jpg', 'app/images/*.png'])
.pipe(imagemin({ optimizationLevel: 5, progressive: true, interlaced: true }));
});
//compressing images & handle SVG files
gulp.task('images-deploy', function() {
gulp.src(['app/images/**/*'])
.pipe(gulp.dest('dist/images'));
});
//compiling our Javascripts
gulp.task('scripts', function() {
//this is where our dev JS scripts are
return gulp.src(['app/scripts/src/_includes/**/*.js', 'app/scripts/src/**/*.js'])
//this is the filename of the compressed version of our JS
.pipe(concat('app.js'))
//catch errors
.on('error', gutil.log)
//compress :D
.pipe(uglify())
//where we will store our finalized, compressed script
.pipe(gulp.dest('app/scripts'))
//notify LiveReload to refresh
.pipe(connect.reload());
});
//compiling our Javascripts for deployment
gulp.task('scripts-deploy', function() {
//this is where our dev JS scripts are
return gulp.src('app/scripts/src/**/*.js')
//this is the filename of the compressed version of our JS
.pipe(concat('app.js'))
//compress :D
.pipe(uglify())
//where we will store our finalized, compressed script
.pipe(gulp.dest('dist/scripts'));
});
//compiling our SCSS files
gulp.task('styles', function() {
//the initializer / master SCSS file, which will just be a file that imports everything
return gulp.src('app/styles/scss/init.scss')
//include SCSS and list every "include" folder
.pipe(sass({
errLogToConsole: true,
includePaths: [
'app/styles/scss/'
]
}))
.pipe(autoprefixer({
browsers: autoPrefixBrowserList,
cascade: true
}))
//catch errors
.on('error', gutil.log)
//the final filename of our combined css file
.pipe(concat('styles.css'))
//where to save our final, compressed css file
.pipe(gulp.dest('app/styles'))
//notify LiveReload to refresh
.pipe(connect.reload());
});
//compiling our SCSS files for deployment
gulp.task('styles-deploy', function() {
//the initializer / master SCSS file, which will just be a file that imports everything
return gulp.src('app/styles/scss/init.scss')
//include SCSS includes folder
.pipe(sass({
includePaths: [
'app/styles/scss',
]
}))
.pipe(autoprefixer({
browsers: autoPrefixBrowserList,
cascade: true
}))
//the final filename of our combined css file
.pipe(concat('styles.css'))
.pipe(minifyCSS())
//where to save our final, compressed css file
.pipe(gulp.dest('dist/styles'));
});
//basically just keeping an eye on all HTML files
gulp.task('html', function() {
//watch any and all HTML files and refresh when something changes
return gulp.src('app/*.html')
.pipe(connect.reload())
//catch errors
.on('error', gutil.log);
});
//migrating over all HTML files for deployment
gulp.task('html-deploy', function() {
//grab everything, which should include htaccess, robots, etc
gulp.src('app/*')
.pipe(gulp.dest('dist'));
//grab any hidden files too
gulp.src('app/.*')
.pipe(gulp.dest('dist'));
gulp.src('app/fonts/**/*')
.pipe(gulp.dest('dist/fonts'));
//grab all of the styles
gulp.src(['app/styles/*.css', '!app/styles/styles.css'])
.pipe(gulp.dest('dist/styles'));
});
//cleans our dist directory in case things got deleted
gulp.task('clean', function() {
del('dist');
});
//this is our master task when you run `gulp` in CLI / Terminal
//this is the main watcher to use when in active development
// this will:
// startup the web server,
// start up livereload
// compress all scripts and SCSS files
gulp.task('default', ['connect', 'scripts', 'styles'], function() {
//a list of watchers, so it will watch all of the following files waiting for changes
gulp.watch('app/scripts/src/**', ['scripts']);
gulp.watch('app/styles/scss/**', ['styles']);
gulp.watch('app/images/**', ['images']);
gulp.watch('app/*.html', ['html']);
});
//this is our deployment task, it will set everything for deployment-ready files
gulp.task('deploy', ['clean'], function () {
gulp.start('scripts-deploy', 'styles-deploy', 'html-deploy', 'images-deploy');
});