-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·167 lines (147 loc) · 5.83 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
// Grab our gulp packages
var gulp = require('gulp'),
gutil = require('gulp-util'),
sass = require('gulp-sass'),
cssnano = require('gulp-cssnano'),
autoprefixer = require('gulp-autoprefixer'),
sourcemaps = require('gulp-sourcemaps'),
jshint = require('gulp-jshint'),
stylish = require('jshint-stylish'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
plumber = require('gulp-plumber'),
bower = require('gulp-bower'),
babel = require('gulp-babel'),
browserSync = require('browser-sync').create();
// Compile Sass, Autoprefix and minify
gulp.task('styles', function() {
return gulp.src('./assets/scss/**/*.scss')
.pipe(plumber(function(error) {
gutil.log(gutil.colors.red(error.message));
this.emit('end');
}))
.pipe(sourcemaps.init()) // Start Sourcemaps
.pipe(sass({
style: 'expanded',
sourceComments: 'normal'
}))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('./assets/css/'))
.pipe(rename({suffix: '.min'}))
.pipe(cssnano())
.pipe(sourcemaps.write('.')) // Creates sourcemaps for minified styles
.pipe(gulp.dest('./assets/css/'))
});
// JSHint, concat, and minify JavaScript
gulp.task('site-js', function() {
return gulp.src([
// Grab your custom scripts
'./assets/js/scripts/*.js'
])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(concat('scripts.js'))
.pipe(gulp.dest('./assets/js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(sourcemaps.write('.')) // Creates sourcemap for minified JS
.pipe(gulp.dest('./assets/js'))
});
// JSHint, concat, and minify Foundation JavaScript
gulp.task('foundation-js', function() {
return gulp.src([
// Foundation core - needed if you want to use any of the components below
'./bower_components/foundation-sites/js/foundation.core.js',
'./bower_components/foundation-sites/js/foundation.util.*.js',
// Pick the components you need in your project
'./bower_components/foundation-sites/js/foundation.abide.js',
'./bower_components/foundation-sites/js/foundation.accordion.js',
'./bower_components/foundation-sites/js/foundation.accordionMenu.js',
'./bower_components/foundation-sites/js/foundation.drilldown.js',
'./bower_components/foundation-sites/js/foundation.dropdown.js',
'./bower_components/foundation-sites/js/foundation.dropdownMenu.js',
'./bower_components/foundation-sites/js/foundation.equalizer.js',
'./bower_components/foundation-sites/js/foundation.interchange.js',
'./bower_components/foundation-sites/js/foundation.magellan.js',
'./bower_components/foundation-sites/js/foundation.offcanvas.js',
'./bower_components/foundation-sites/js/foundation.orbit.js',
'./bower_components/foundation-sites/js/foundation.responsiveMenu.js',
'./bower_components/foundation-sites/js/foundation.responsiveToggle.js',
'./bower_components/foundation-sites/js/foundation.reveal.js',
'./bower_components/foundation-sites/js/foundation.slider.js',
'./bower_components/foundation-sites/js/foundation.sticky.js',
'./bower_components/foundation-sites/js/foundation.tabs.js',
'./bower_components/foundation-sites/js/foundation.toggler.js',
'./bower_components/foundation-sites/js/foundation.tooltip.js',
'./bower_components/foundation-sites/js/foundation.util.motion.js'
])
.pipe(babel({
presets: ['es2015'],
compact: true
}))
.pipe(sourcemaps.init())
.pipe(concat('foundation.js'))
.pipe(gulp.dest('./assets/js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(sourcemaps.write('.')) // Creates sourcemap for minified Foundation JS
.pipe(gulp.dest('./assets/js'))
});
// JSHint, concat, and minify Foundation JavaScript
gulp.task('what-input-js', function() {
return gulp.src([
// Foundation core - needed if you want to use any of the components below
'./bower_components/what-input/what-input.js'
])
.pipe(babel({
presets: ['es2015'],
compact: true
}))
.pipe(sourcemaps.init())
.pipe(concat('what-input.js'))
.pipe(gulp.dest('./assets/js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(sourcemaps.write('.')) // Creates sourcemap for minified Foundation JS
.pipe(gulp.dest('./assets/js'))
});
// Update Foundation with Bower and save to /bower_components
gulp.task('bower', function() {
return bower({ cmd: 'update'})
.pipe(gulp.dest('bower_components/'))
});
// Browser-Sync watch files and inject changes
gulp.task('browsersync', function() {
// Watch files
var files = [
'./assets/css/*.css',
'./assets/js/*.js',
'**/*.php',
'assets/images/**/*.{png,jpg,gif,svg,webp}',
];
browserSync.init(files, {
// Replace with URL of your local site
proxy: "http://localhost/",
});
gulp.watch('./assets/scss/**/*.scss', ['styles']);
gulp.watch('./assets/js/scripts/*.js', ['site-js']).on('change', browserSync.reload);
});
// Watch files for changes (without Browser-Sync)
gulp.task('watch', function() {
// Watch .scss files
gulp.watch('./assets/scss/**/*.scss', ['styles']);
// Watch site-js files
gulp.watch('./assets/js/scripts/*.js', ['site-js']);
// Watch foundation-js files
gulp.watch('./bower_components/foundation-sites/js/*.js', ['foundation-js']);
});
// Run styles, site-js and foundation-js
gulp.task('default', function() {
gulp.start('styles', 'site-js', 'foundation-js', 'what-input-js' );
});