-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpfile.babel.js
159 lines (142 loc) · 6.26 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
// Import configuration settings (file name has .babel so it can use es6 modules)
import {
source,
limbo,
dest,
useSourcemaps,
minify,
sassArray,
jsArray,
usableBabelIgnore,
removeUnusedCss,
pageArray,
images,
imageDest,
} from './gulp.config';
// Packages for Gulp
const gulp = require('gulp'); // https://github.com/gulpjs/gulp
const plumber = require('gulp-plumber'); // https://github.com/floatdrop/gulp-plumber
const gulpif = require('gulp-if'); // https://github.com/robrich/gulp-if
const image = require('gulp-image'); // https://github.com/1000ch/gulp-image
const sourcemaps = require('gulp-sourcemaps'); // https://github.com/floridoo/gulp-sourcemaps
const sass = require('gulp-sass'); // https://github.com/dlmanning/gulp-sass
const babel = require('gulp-babel'); // https://github.com/babel/gulp-babel
const uncss = require('gulp-uncss'); // https://github.com/ben-eb/gulp-uncss
const postcss = require('gulp-postcss'); // https://github.com/postcss/gulp-postcss
const mqpacker = require('css-mqpacker'); // https://github.com/hail2u/node-css-mqpacker
const cssnano = require('cssnano'); // https://github.com/ben-eb/gulp-cssnano
const autoprefixer = require('gulp-autoprefixer'); // https://github.com/sindresorhus/gulp-autoprefixer
const flexbugs = require('postcss-flexbugs-fixes'); // https://github.com/luisrudge/postcss-flexbugs-fixes
const concat = require('gulp-concat'); // https://github.com/contra/gulp-concat
const uglify = require('gulp-uglify'); // https://github.com/terinjokes/gulp-uglify
const rev = require('gulp-rev'); // https://github.com/sindresorhus/gulp-rev
const revReplace = require('gulp-rev-replace'); // https://github.com/jamesknelson/gulp-rev-replace
const revDel = require('rev-del'); // https://github.com/callumacrae/rev-del
// Separate php tasks for performance
gulp.task('phpClasses', () => {
return gulp.src('development/includes/classes/**/**.php', { base: 'development/includes/classes' })
.pipe(plumber())
.pipe(gulp.dest(`${dest}includes/classes`));
});
gulp.task('phpFunctions', () => {
return gulp.src('development/includes/functions/**/**.php', { base: 'development/includes/functions' })
.pipe(plumber())
.pipe(gulp.dest(`${dest}includes/functions`));
});
gulp.task('phpParts', () => {
return gulp.src('development/includes/parts/**/**.php', { base: 'development/includes/parts' })
.pipe(plumber())
.pipe(gulp.dest(`${dest}includes/parts`));
});
gulp.task('phpSections', () => {
return gulp.src('development/includes/sections/**/**.php', { base: 'development/includes/sections' })
.pipe(plumber())
.pipe(gulp.dest(`${dest}includes/sections`));
});
gulp.task('phpPages', () => {
return gulp.src('development/pages/**/**.php', { base: 'development/pages' })
.pipe(plumber())
.pipe(gulp.dest(dest));
});
// Sassify, optimize, automatically prefix, and minify css
gulp.task('sass', () => {
return gulp.src(sassArray, { base: 'development/sass' })
.pipe(plumber())
.pipe(gulpif(useSourcemaps, sourcemaps.init()))
.pipe(sass())
.pipe(gulpif(removeUnusedCss, uncss({ // Remove unused css based on what pages are using
html: pageArray,
})))
.pipe(gulpif(minify, postcss([
flexbugs(), // Fix flexbox bugs for IE 10-11
mqpacker(), // TODO: Can somtimes break?
cssnano(), // css minifier
])))
.pipe(autoprefixer())
.pipe(gulpif(useSourcemaps, sourcemaps.write('maps')))
.pipe(gulp.dest(`${limbo}css`));
});
// Babelfy, minify and then combine js files
gulp.task('javascript', () => {
return gulp.src(jsArray, { base: 'development/js' })
.pipe(plumber())
.pipe(gulpif(useSourcemaps, sourcemaps.init()))
.pipe(babel({ // convert latest js into browser ready js
presets: ['latest'],
// Ignore seems to mean only and vice versa...
only: usableBabelIgnore,
}))
.pipe(concat('all.js')) // concatenate all js into a single file
.pipe(gulpif(minify, uglify())) // js minifier
.pipe(gulpif(useSourcemaps, sourcemaps.write('maps')))
.pipe(gulp.dest(`${limbo}js`));
});
// Rename assets based on content cache
gulp.task('sassRevisions', ['sass'], () => {
return gulp.src(`${limbo}**/**/**/*.css`, { base: 'limbo/' })
.pipe(plumber())
.pipe(rev())
.pipe(gulp.dest(dest))
.pipe(rev.manifest('assets/css/manifest.json'))
.pipe(revDel({ dest, force: true })) // force: true so that revDel can delete files above itself
.pipe(gulp.dest(dest));
});
// Rename assets based on content cache
gulp.task('jsRevisions', ['javascript'], () => {
return gulp.src(`${limbo}**/**/**/*.js`, { base: 'limbo/' })
.pipe(plumber())
.pipe(rev())
.pipe(gulp.dest(dest))
.pipe(rev.manifest('assets/js/manifest.json'))
.pipe(revDel({ dest, force: true })) // force: true so that revDel can delete files above itself
.pipe(gulp.dest(dest));
});
gulp.task('maps', ['jsRevisions', 'sassRevisions'], () => {
return gulp.src(`${limbo}**/**/**/*.map`, { base: 'limbo/' })
.pipe(plumber())
.pipe(gulp.dest(dest));
});
gulp.task('imageoptim', () => {
return gulp.src(`${source}images/**/*.{jpg,JPG,jpeg,JPEG,png,PNG,gif,GIF,svg,SVG,ico}`)
.pipe(plumber())
.pipe(image())
.pipe(gulp.dest(imageDest));
});
// Watch everything and update
if (images === true) {
gulp.task('watch', () => {
gulp.watch(`${source}images/**/*.{jpg,JPG,jpeg,JPEG,png,PNG,gif,GIF,svg,SVG,ico}`, ['imageoptim']);
});
gulp.task('default', ['imageoptim', 'watch']);
} else {
gulp.task('watch', () => {
gulp.watch(`${source}**/**/**/*.{css,scss}`, ['sassRevisions']);
gulp.watch(`${source}**/**/**/*.js`, ['jsRevisions']);
gulp.watch(`${source}includes/classes/**/*.php`, ['phpClasses']);
gulp.watch(`${source}includes/functions/**/*.php`, ['phpFunctions']);
gulp.watch(`${source}includes/parts/**/*.php`, ['phpParts']);
gulp.watch(`${source}includes/sections/**/*.php`, ['phpSections']);
gulp.watch(`${source}pages/**/*.php`, ['phpPages']);
});
gulp.task('default', ['sassRevisions', 'jsRevisions', 'phpClasses', 'phpFunctions', 'phpParts', 'phpSections', 'phpPages', 'maps', 'watch']);
}