-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathgulpfile.js
178 lines (160 loc) · 4.46 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Gulp
var gulp = require('gulp');
// Plugins
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync');
var cache = require('gulp-cache');
var concat = require('gulp-concat');
var del = require('del');
var imagemin = require('gulp-imagemin');
var jshint = require('gulp-jshint');
var minifyCSS = require('gulp-minify-css');
var notify = require('gulp-notify'); // Requires Growl on Windows
var plumber = require('gulp-plumber');
var rename = require('gulp-rename');
var runSequence = require('run-sequence');
var sass = require('gulp-ruby-sass'); // Requires Ruby
var uglify = require('gulp-uglify');
// Define our Paths
var paths = {
scripts: 'js/**/*.js',
styles: 'sass/**/*.scss',
fonts: 'sass/fonts/*',
images: 'img/**/*.{png,jpg,jpeg,gif}',
bowerDir: './bower_components'
};
var destPaths = {
scripts: 'build/js',
styles: 'build/css',
fonts: 'build/fonts',
images: 'build/img/'
};
// Error Handling
// Send error to notification center with gulp-notify
var handleErrors = function() {
notify.onError({
title: "Compile Error",
message: "<%= error.message %>"
}).apply(this, arguments);
this.emit('end');
};
// Compile our SASS
gulp.task('styles', function() {
return gulp.src(paths.styles)
.pipe(plumber())
.pipe(sass({
sourcemap: true,
sourcemapPath: paths.styles,
loadPath: [
paths.bowerDir + '/bootstrap-sass-official/assets/stylesheets',
paths.bowerDir + '/fontawesome/scss',
]
}))
.pipe(autoprefixer())
.pipe(gulp.dest(destPaths.styles))
.pipe(notify('Styles task complete!'));
});
// Compile and Minify our SASS for Build
gulp.task('build-styles', function() {
return gulp.src(paths.styles)
.pipe(plumber())
.pipe(sass({
loadPath: [
paths.bowerDir + '/bootstrap-sass-official/assets/stylesheets',
paths.bowerDir + '/fontawesome/scss',
]
}))
.pipe(autoprefixer({
cascade: false
}))
.pipe(minifyCSS())
.pipe(gulp.dest(destPaths.styles))
.pipe(notify('Build styles task complete!'));
});
// Lint, Minify, and Concat our JS
gulp.task('scripts', function() {
return gulp.src(paths.scripts)
.pipe(plumber())
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(uglify())
.pipe(concat('main.min.js'))
.pipe(gulp.dest(destPaths.scripts))
.pipe(notify('Scripts tasks complete!'));
});
// Clean Images Folder
gulp.task('clean-images', function(cb) {
del([destPaths.images], cb);
});
// Move Images to Build Folder
gulp.task('images', ['clean-images'], function() {
return gulp.src(paths.images)
.pipe(plumber())
.pipe(gulp.dest(destPaths.images))
.pipe(notify('Image optimized!'));
});
// Compress Images for Build
gulp.task('build-images', function() {
return gulp.src(paths.images)
.pipe(plumber())
.pipe(imagemin({
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(destPaths.images))
.pipe(notify('Image optimized!'));
});
// Watch for changes made to files
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['scripts']);
gulp.watch(paths.styles, ['styles']);
gulp.watch('dist/_juice.scss', ['styles']);
gulp.watch(paths.images, ['images']);
});
// Browser Sync - autoreload the browser
// Additional Settings: http://www.browsersync.io/docs/options/
gulp.task('browser-sync', function () {
var files = [
'**/*.html',
'**/*.php',
'build/css/style.css',
'build/js/main.min.js',
'build/img/**/*.{png,jpg,jpeg,gif}'
];
browserSync.init(files, {
server: {
baseDir: './'
},
// proxy: 'juice.github.dev', // Proxy for local dev sites
port: 5555, // Sets the port in which to serve the site
open: false, // Stops BS from opening a new browser window
// ghostMode: { // Disable ghosting features (Useful when sharing a link for people to troubleshoot)
// clicks: false,
// location: false,
// forms: false,
// scroll: false
// },
logPrefix: "Juice" // Display a different prefix in the command line
});
});
// Clean Build Folder
gulp.task('clean', function(cb) {
del(['build'], cb);
});
// Clear the cache for everything
gulp.task('clear-cache', function() {
cache.clearAll();
});
// Move Fonts to Build Folder
gulp.task('move-fonts', function() {
gulp.src(paths.fonts)
.pipe(gulp.dest(destPaths.fonts));
});
// Default Task
gulp.task('default', function(cb) {
runSequence('clean', 'clear-cache', 'images', 'scripts', 'styles', 'move-fonts', 'browser-sync', 'watch', cb);
});
// Build Task
gulp.task('build', function(cb) {
runSequence('clean', 'clear-cache', 'build-images', 'build-styles', 'scripts', 'move-fonts', cb);
});