-
Notifications
You must be signed in to change notification settings - Fork 107
/
gulpfile.js
177 lines (151 loc) · 3.75 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
const gulp = require('gulp')
const sass = require('gulp-sass')(require('sass'))
const clean = require('gulp-clean')
const rename = require('gulp-rename')
const cleanCSS = require('gulp-clean-css')
const uglify = require('gulp-uglify')
const zip = require('gulp-zip')
const webpack = require('webpack-stream')
const { version } = require('./package.json')
/**
* Import gulp tasks used for creating
* our website pages.
*/
require('./tasks/docs.js')
/* Remove all compiled files */
function cleanDist() {
return gulp.src('dist', { allowEmpty: true }).pipe(clean())
}
/**
* CSS tasks
*/
sass.compiler = require('sass')
/* Build the CSS from source */
function compileCSS() {
return gulp
.src(['packages/nhsuk.scss'])
.pipe(sass())
.pipe(gulp.dest('dist/'))
.on('error', (err) => {
console.log(err)
process.exit(1)
})
}
/* Minify CSS and add a min.css suffix */
function minifyCSS() {
return gulp
.src([
'dist/*.css',
'!dist/*.min.css' // don't re-minify minified css
])
.pipe(cleanCSS())
.pipe(
rename({
suffix: `-${version}.min`
})
)
.pipe(gulp.dest('dist/'))
}
/**
* JavaScript tasks
*/
/* Use Webpack to build and minify the NHS.UK components JS. */
function webpackJS() {
return gulp
.src('./packages/nhsuk.js')
.pipe(
webpack({
mode: 'production',
module: {
rules: [
{
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
output: {
filename: 'nhsuk.js'
},
target: 'web'
})
)
.pipe(gulp.dest('./dist'))
}
/* Minify the JS file for release */
function minifyJS() {
return gulp
.src([
'dist/*.js',
'!dist/*.min.js' // don't re-minify minified javascript
])
.pipe(uglify())
.pipe(
rename({
suffix: '.min'
})
)
.pipe(gulp.dest('dist/'))
}
/* Version the JS file for release */
function versionJS() {
return gulp
.src([
'dist/*.js',
'!dist/*.min.js' // don't re-minify minified javascript
])
.pipe(uglify())
.pipe(
rename({
suffix: `-${version}.min`
})
)
.pipe(gulp.dest('dist/'))
}
/**
* Assets tasks
*/
/**
* Copy assets such as icons and images into the distribution
*/
function assets() {
return gulp.src('packages/assets/**').pipe(gulp.dest('dist/assets/'))
}
/**
* Release tasks
*/
/* Copy JS files into their relevant folders */
function jsFolder() {
return gulp.src('dist/*.min.js', '!dist/js/nhsuk.min.js').pipe(clean()).pipe(gulp.dest('dist/js/'))
}
/* Copy CSS files into their relevant folders */
function cssFolder() {
return gulp.src('dist/*.min.css').pipe(clean()).pipe(gulp.dest('dist/css/'))
}
function createZip() {
return gulp
.src(['dist/css/*.min.css', 'dist/js/*.min.js', 'dist/assets/**', '!dist/js/nhsuk.min.js'], { base: 'dist' })
.pipe(zip(`nhsuk-frontend-${version}.zip`))
.pipe(gulp.dest('dist'))
}
/**
* Development tasks
*/
/* Recompile CSS, JS and docs when there are any changes */
function watch() {
gulp.watch(['packages/**/*', 'app/**/*'], gulp.series(['build', 'docs:build']))
}
gulp.task('clean', cleanDist)
gulp.task('style', compileCSS)
gulp.task('build', gulp.series([compileCSS, webpackJS]))
gulp.task('bundle', gulp.series([cleanDist, 'build', minifyCSS, minifyJS, versionJS]))
gulp.task('zip', gulp.series(['bundle', assets, jsFolder, cssFolder, createZip]))
gulp.task('watch', watch)
/**
* The default task is to build everything, serve the docs and watch for changes
*/
gulp.task('default', gulp.series([cleanDist, 'build', gulp.parallel(['docs:serve', watch])]))