-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
194 lines (171 loc) · 4.48 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
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
*
* Gulp tasks for the NISP Assets (CSS/Javascript/Images).
*
* This file was originally created by Savaslabs.
* See: http://savaslabs.com/2016/10/19/optimizing-jekyll-with-gulp.html
*
* Table of contents:
* 1. Styles
* 2. Scripts
* 3. Images
* 4. Fonts
* 5. Misc.
*/
// Define variables.
var appendPrepend = require('gulp-append-prepend');
var autoprefixer = require('autoprefixer');
var browserSync = require('browser-sync').create();
var cache = require('gulp-cache');
var cleancss = require('gulp-clean-css');
var concat = require('gulp-concat');
var del = require('del');
var gulp = require('gulp');
var gutil = require('gulp-util');
var imagemin = require('gulp-imagemin');
var jpegRecompress = require('imagemin-jpeg-recompress');
var notify = require('gulp-notify');
var postcss = require('gulp-postcss');
var rename = require('gulp-rename');
var run = require('gulp-run');
var runSequence = require('run-sequence');
var sass = require('gulp-ruby-sass');
var uglify = require('gulp-uglify');
/**
* Task: build:styles:main
*
* Uses Sass compiler to process styles, adds vendor prefixes, minifies, then
* outputs file to the appropriate location.
*/
gulp.task('build:styles:nisp', function() {
return sass('scss' + '/nisp.scss', {
style: 'compressed',
trace: true,
loadPath: ['scss/']
}).pipe(postcss([ autoprefixer({ browsers: ['last 2 versions'] }) ]))
.pipe(cleancss())
.pipe(gulp.dest('xsl/css/'))
.pipe(gulp.dest('build/css/'))
.pipe(browserSync.stream())
.on('error', gutil.log);
});
gulp.task('build:styles:man', function() {
return sass('scss' + '/man.scss', {
style: 'compressed',
trace: true,
loadPath: ['scss/']
}).pipe(postcss([ autoprefixer({ browsers: ['last 2 versions'] }) ]))
.pipe(cleancss())
.pipe(gulp.dest('xsl/css/'))
.pipe(gulp.dest('build/css/'))
.pipe(browserSync.stream())
.on('error', gutil.log);
});
/**
* Task: build:styles:css
*
* Copies any other CSS files to the assets directory, to be used by pages/posts
* that specify custom CSS files.
*/
gulp.task('build:styles:css', function() {
return gulp.src(['scss' + '/*.css'])
.pipe(postcss([ autoprefixer({ browsers: ['last 2 versions'] }) ]))
.pipe(cleancss())
.pipe(gulp.dest('xsl/css'))
.pipe(gulp.dest('build/css'))
.on('error', gutil.log);
});
/**
* Task: build:styles
*
* Builds all site styles.
*/
gulp.task('build:styles', [
'build:styles:nisp',
'build:styles:man',
'build:styles:css'
]);
/**
* Task: clean:styles
*
* Deletes all processed site styles.
*/
gulp.task('clean:styles', function(callback) {
del(['xsl/css/', 'build/css/']);
callback();
});
/**
* Task: clean
*
* Runs all the clean commands.
*/
gulp.task('clean', [
'clean:styles']);
/**
* Task: build
*
* Build the assets.
*/
gulp.task('build', function(callback) {
runSequence('clean',
['build:styles'],
callback);
});
/**
* Task: build:test
*
* Builds the site anew using test config.
*/
gulp.task('build:test', function(callback) {
runSequence('clean',
['build:styles'],
callback);
});
/**
* Task: build:test
*
* Builds the site anew using test and local config.
*/
gulp.task('build:local', function(callback) {
runSequence('clean',
['build:styles'],
callback);
});
/**
* Task: default
*
* Builds the site anew.
*/
gulp.task('default', ['build']);
/**
* Task: serve
*
* Static Server + watching files.
*
* Note: passing anything besides hard-coded literal paths with globs doesn't
* seem to work with gulp.watch().
*/
gulp.task('serve', ['build:local'], function() {
browserSync.init({
server: 'build/',
ghostMode: false, // Toggle to mirror clicks, reloads etc. (performance)
logFileChanges: true,
logLevel: 'debug',
open: true // Toggle to automatically open page when starting.
});
// Watch .scss files; changes are piped to browserSync.
// Ignore style guide SCSS.
// Rebuild the style guide to catch updates to component markup.
gulp.watch(
['scss/**/*.scss'],
['build:styles']
);
});
/**
* Task: cache-clear
*
* Clears the gulp cache. Currently this just holds processed images.
*/
gulp.task('cache-clear', function(done) {
return cache.clearAll(done);
});