-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.babel.js
267 lines (233 loc) · 5.54 KB
/
gulpfile.babel.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/**
* Gulp Packages
* =============
* Import our gulp packages.
*/
import gulp from 'gulp';
import autoprefixer from 'autoprefixer';
import babel from 'gulp-babel';
import BabiliPlugin from 'babili-webpack-plugin';
import browserSync from 'browser-sync';
import cheerio from 'gulp-cheerio';
import concat from 'gulp-concat';
import eslint from 'gulp-eslint';
import gulpStylelint from 'gulp-stylelint';
import header from 'gulp-header';
import imagemin from 'gulp-imagemin';
import modernizr from 'gulp-modernizr';
import path from 'path';
import plumber from 'gulp-plumber';
import pngquant from 'imagemin-pngquant';
import postcss from 'gulp-postcss';
import rename from 'gulp-rename';
import sass from 'gulp-sass';
import sourcemaps from 'gulp-sourcemaps';
import svgmin from 'gulp-svgmin';
import svgstore from 'gulp-svgstore';
import uglify from 'gulp-uglify';
import webpack from 'webpack';
import webpackStream from 'webpack-stream';
/**
* Constants
* ---------
* Constants used throughout this boilerplate.
*/
import pkg from './package.json';
import options from './gulp-options.json';
/**
* Banner Template
* ---------------
* Define our banner template which is injected into
* the top of our minfied Stylesheet and JavaScript.
*/
const banner = [
`/*!
* ${pkg.name}
* ${pkg.title}
* ${pkg.url}
* @author ${pkg.author}
* @version ${pkg.version}
* Copyright ${new Date().getFullYear()}. ${pkg.license} licensed.
*/`,
'\n'
].join('');
/**
* BrowserSync.io
* --------------
* - Runs css, js, images and svg-sprite tasks
* - Serve project on: localhost:3000
* - Watch css, js, images and svg files for changes
*/
gulp.task('serve', [
'lint-sass',
'sass',
'lint-js',
'js',
'modernizr',
'images',
'svg-sprite'
], () => {
browserSync.init({
server: options.dest.dist
});
gulp.watch(options.src.scss, ['lint-sass', 'sass']);
gulp.watch(options.src.js, ['lint-js', 'js', 'modernizr']);
gulp.watch(options.src.img, ['images']);
gulp.watch(options.src.sprite, ['svg-sprite']);
gulp.watch(`${options.dest.dist}/*.html`).on('change', browserSync.reload);
});
/**
* Sass
* -------
* - Assign plugins to processors variable
* - Create sourcemaps
* - Process css with PostCSS
* - Inject banner into finished file
* - Add .min suffix
* - Copy to destination
*/
gulp.task('sass', () => {
return gulp.src(options.src.scss)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass({
includePaths: [
options.dep.normalize,
options.dep.avalancheCss
],
outputStyle: 'compressed',
errLogToConsole: true
}))
.pipe(postcss([
autoprefixer({
browsers: options.support.browser,
cascade: false
})
]))
.pipe(header(banner, {
pkg: pkg
}))
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(options.dest.css))
.pipe(browserSync.reload({
stream: true,
once: true
}))
});
/**
* Lint Sass
* -------
* - Lints src files with stylelint
*/
gulp.task('lint-sass', () => {
return gulp
.src(options.src.scss)
.pipe(gulpStylelint({
reporters: [{
formatter: 'string',
console: true
}],
failAfterError: false,
syntax: "scss"
}));
});
/*
* JavaScript
* ----------
* - Bundle JavaScript with Webpack
* - Copy to destination
* - Reload BrowserSync
*/
gulp.task('js', () => {
return gulp
.src(options.src.js)
.pipe(webpackStream({
devtool: 'source-map',
output: {
filename: 'app.min.js',
},
module: {
loaders: [{
loader: 'babel-loader',
test: /\.js$/,
exclude: /(node_modules|assets)\/(?![@contentdiscovered/ozpin|@contentdiscovered/flack])/,
query: {
presets: ['es2015'],
},
}],
},
plugins: [
new BabiliPlugin(),
],
}, webpack))
.pipe(gulp.dest(options.dest.js))
.pipe(browserSync.stream());
});
/**
* Modernizr
* ---------
* - Scan src JavaScript files for Modernizr checks
* - Build production Modernizr
* - Copy to destination
* - Reload browsersync
*/
gulp.task('modernizr', () => {
return gulp
.src(options.src.js)
.pipe(modernizr('modernizr-build.min.js'))
.pipe(gulp.dest(options.dest.vendor))
.pipe(browserSync.reload({
stream: true,
once: true
}))
});
/**
* Lint JavaScript
* ----------
* - Lint source files with eslint
*/
gulp.task('lint-js', () => {
return gulp.src(options.src.js)
.pipe(eslint())
.pipe(eslint.format())
});
/**
* Image Optimisation
* ------------------
* - Compress images
* - Copy to destination
* - Reload BrowserSync
*/
gulp.task('images', () => {
return gulp.src(options.src.img)
.pipe(imagemin({
progressive: true,
svgoPlugins: [{
removeViewBox: false
}],
use: [pngquant()]
}))
.pipe(gulp.dest(options.dest.img))
.pipe(browserSync.stream())
});
/**
* SVG Sprite
* ----------
* - Define prefix based on folder name
* - Sprite svg's
* - Copy sprite.svg to destination
* - Reload BrowserSync
*/
gulp.task('svg-sprite', () => {
return gulp.src(options.src.sprite)
.pipe(svgmin())
.pipe(svgstore())
.pipe(cheerio($ => $('svg').attr('style', 'display:none')))
.pipe(gulp.dest(options.dest.img))
.pipe(browserSync.stream())
});
// Default Task
gulp.task('default', ['serve']);
// Build Task
gulp.task('build', ['lint-sass', 'sass', 'lint-js', 'js', 'modernizr', 'images', 'svg-sprite']);