-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
183 lines (117 loc) · 6.01 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
179
180
181
var gulp = require('gulp'); // Gulp!
var plumber = require('gulp-plumber');
var sass = require('gulp-sass'); // Sass
var prefix = require('gulp-autoprefixer'); // Autoprefixr
var minifycss = require('gulp-minify-css'); // Minify CSS
var concat = require('gulp-concat'); // Concat files
var uglify = require('gulp-uglify'); // Uglify javascript
var svgmin = require('gulp-svgmin'); // SVG minify
var imagemin = require('gulp-imagemin'); // Image minify
var rename = require('gulp-rename'); // Rename files
var util = require('gulp-util'); // Writing stuff
var livereload = require('gulp-livereload'); // LiveReload
var jshint = require("gulp-jshint"); // jshint
//
// Compile all CSS for the site
//
//////////////////////////////////////////////////////////////////////
gulp.task('sass', function (){
gulp.src([
'bower_components/foundation/scss/normalize.scss', // Gets normalize
'assets/scss/app.scss']) // Gets the apps scss
.pipe(plumber())
.pipe(sass({style: 'compressed', errLogToConsole: true})) // Compile sass
.pipe(concat('app.css')) // Concat all css
// .pipe(rename({suffix: '.min'})) // Rename it
// .pipe(minifycss()) // Minify the CSS
.pipe(gulp.dest('assets/css/')) // Set the destination to assets/css
.pipe(livereload()); // Reloads server
util.log(util.colors.yellow('Sass compiled & minified')); // Output to terminal
});
//
// Get all the JS, concat and uglify
//
//////////////////////////////////////////////////////////////////////
gulp.task('javascripts', function(){
gulp.src([
'bower_components/jquery/dist/jquery.min.js', // Gets Jquery
'bower_components/fastclick/lib/fastclick.js', // Gets fastclick
// Gets Foundation JS change to only include the scripts you'll need
'bower_components/foundation/js/foundation/foundation.js',
// 'bower_components/foundation/js/foundation/foundation.abide.js',
// 'bower_components/foundation/js/foundation/foundation.accordion.js',
// 'bower_components/foundation/js/foundation/foundation.alert.js',
// 'bower_components/foundation/js/foundation/foundation.clearing.js',
// 'bower_components/foundation/js/foundation/foundation.dropdown.js',
// 'bower_components/foundation/js/foundation/foundation.equalizer.js',
// 'bower_components/foundation/js/foundation/foundation.interchange.js',
// 'bower_components/foundation/js/foundation/foundation.joyride.js',
// 'bower_components/foundation/js/foundation/foundation.magellan.js',
// 'bower_components/foundation/js/foundation/foundation.offcanvas.js',
// 'bower_components/foundation/js/foundation/foundation.orbit.js',
// 'bower_components/foundation/js/foundation/foundation.reveal.js',
// 'bower_components/foundation/js/foundation/foundation.slider.js',
// 'bower_components/foundation/js/foundation/foundation.tab.js',
// 'bower_components/foundation/js/foundation/foundation.tooltip.js',
'bower_components/foundation/js/foundation/foundation.topbar.js',
// moving on...
'assets/js/**/_*.js']) // Gets all the user JS _*.js from assets/js
.pipe(concat('scripts.js')) // Concat all the scripts
.pipe(rename({suffix: '.min'})) // Rename it
.pipe(uglify().on('error', function(e) { console.log('\x07',e.message); return this.end(); })) // Uglify(minify)
.pipe(gulp.dest('assets/js/')) // Set destination to assets/js
.pipe(livereload()); // Reloads server
util.log(util.colors.yellow('Javascripts compiled and minified')); // Output to terminal
});
//
// Copy bower components to assets-folder
//
//////////////////////////////////////////////////////////////////////
gulp.task('copy', function(){
gulp.src('bower_components/modernizr/modernizr.js') // Gets Modernizr.js
.pipe(uglify()) // Uglify(minify)
.pipe(rename({suffix: '.min'})) // Rename it
.pipe(gulp.dest('assets/js/')); // Set destination to assets/js
util.log(util.colors.yellow('Files copied')); // Output to terminal
});
//
// JS hint
//
//////////////////////////////////////////////////////////////////////
gulp.task('jshint', function() {
gulp.src('assets/js/_*.js')
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
//
// Minify all SVGs and images
//
//////////////////////////////////////////////////////////////////////
gulp.task('svgmin', function() {
gulp.src(['assets/img/*.svg', 'assets/royalSlider/custom-skin/*.svg']) // Gets all SVGs
.pipe(svgmin()) // Minifies SVG
.pipe(gulp.dest('assets/img_min/')); // Set destination to assets/img_min/
util.log(util.colors.yellow('SVGs minified')); // Output to terminal
});
gulp.task('imagemin', function () {
gulp.src(['assets/img/*', '!assets/img/*.svg']) // Gets all images except SVGs
.pipe(imagemin()) // Minifies
.pipe(gulp.dest('assets/img_min/')); // Set destination to assets/img_min/
util.log(util.colors.yellow('Images minified')); // Output to terminal
});
//
// Default gulp task.
//
//////////////////////////////////////////////////////////////////////
gulp.task('watch', function(){
var server = livereload();
gulp.watch('**/*.php').on('change', function(file) {
server.changed(file.path);
util.log(util.colors.yellow('PHP file changed' + ' (' + file.path + ')'));
});
gulp.watch("bower_components/foundation/scss/**/*.scss", ['sass']); // Runs sass on foundation components change
gulp.watch("assets/scss/**/*.scss", ['sass']); // Watch and run sass on changes
gulp.watch("assets/js/_*.js", ['jshint', 'javascripts']); // Watch and run javascripts on changes
gulp.watch("assets/img/*", ['imagemin', 'svgmin']); // Watch and minify images on changes
});
gulp.task('default', ['sass', 'jshint', 'javascripts', 'copy', 'watch']);