-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
152 lines (137 loc) · 3.34 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
/**
* Load Gulp and Gulp-adjacent dependencies
*/
const gulp = require('gulp')
const gutil = require('gulp-util')
const concat = require('gulp-concat')
const cssnano = require('gulp-cssnano')
const eyeglass = require('eyeglass')
const imagemin = require('gulp-imagemin')
const minimist = require('minimist')
const sass = require('gulp-sass')
const sassAssetFuncs = require('node-sass-asset-functions')
const sassglob = require('gulp-sass-glob')
const sourcemaps = require('gulp-sourcemaps')
const svgo = require('gulp-svgo')
const svgSprite = require('gulp-svg-sprite')
const uglify = require('gulp-uglify')
const webpack = require('webpack-stream')
var options = minimist(process.argv.slice(2), {
string: 'env',
default: {
env: process.env.NODE_ENV || 'production'
},
})
/**
* Sass to CSS compilation, minification, and prefixing
*/
gulp.task('css', () => {
const sassConfig = {
functions: sassAssetFuncs({
'images_path': 'build/assets/img/',
'http_images_path': '../img/',
'fonts_path': 'build/assets/fonts/',
'http_fonts_path': '../fonts/',
}),
includePaths: [
'./node_modules',
],
}
let stream = gulp.src('src/assets/sass/*.scss')
.pipe(sassglob())
.pipe(sourcemaps.init())
.pipe(sass(eyeglass(sassConfig)).on('error', sass.logError))
.pipe(cssnano({
autoprefixer: {
browsers: ['last 2 versions'],
cascade: false,
},
discardComments: {
removeAll: true,
},
zindex: false,
}))
// Write sourcemaps if we're outside of production
stream = (options.env === 'production')
? stream
: stream.pipe(sourcemaps.write())
// Write the output
stream.pipe(gulp.dest('build/assets/css/'))
})
/**
* Font placement
*/
gulp.task('fonts', () => {
gulp.src('src/assets/fonts/**/*')
.pipe(gulp.dest('build/assets/fonts/'))
})
/**
* Image minification
*/
gulp.task('images', () => {
gulp.src('src/assets/img/**/*')
.pipe(imagemin({
progressive: true,
multipass: true,
}))
.pipe(gulp.dest('build/assets/img/'))
})
/**
* Spritify SVGs
*/
gulp.task('sprites', () => {
gulp.src('src/assets/sprites/**/*.svg')
.pipe(svgSprite({
mode: {
symbol: true
}
}))
.pipe(gulp.dest('build/assets/sprites'))
})
/**
* Handle normal SVGs
*/
gulp.task('svg', () => {
gulp.src('src/assets/svg/**/*.svg')
.pipe(svgo())
.pipe(gulp.dest('build/assets/img'))
})
/**
* JavaScript compilation
*/
gulp.task('js', () => {
// Grab the config file
let webpackConfig = require('./webpack.config.js')
gulp.src('src/assets/js/index.js')
.pipe(webpack(webpackConfig[options.env]))
.pipe(gulp.dest('build/assets/js/'))
})
/**
* Watch filesystem for changes
*/
gulp.task('watcher', () => {
const isWatching = true
gulp.watch('src/assets/sass/**/*.scss', ['css'])
gulp.watch('src/assets/fonts/**/*', ['fonts'])
gulp.watch('src/assets/img/**/*', ['images'])
gulp.watch('src/assets/svg/**/*', ['svg'])
gulp.watch('src/assets/sprites/**/*.svg', ['sprites'])
})
/**
* Set up default task
*/
gulp.task('default', [
'images',
'svg',
'sprites',
'js',
'fonts',
'css',
])
/**
* Set up watch task
*/
gulp.task('watch', [
'default',
'watcher',
])