1
0
mirror of https://github.com/kremalicious/blog.git synced 2025-02-14 21:10:25 +01:00

revision all assets in one go

This commit is contained in:
Matthias Kretschmann 2017-03-26 01:17:11 +01:00
parent 1c80c1e29b
commit 213958cf8f
Signed by: m
GPG Key ID: BD3C1F3EDD7831FC

View File

@ -165,6 +165,7 @@ const processors = [
autoprefixer({ browsers: COMPATIBILITY }), autoprefixer({ browsers: COMPATIBILITY }),
cssnano() cssnano()
] ]
export const css = () => export const css = () =>
src([ src([
SRC + '/_assets/styl/kremalicious3.styl', SRC + '/_assets/styl/kremalicious3.styl',
@ -176,41 +177,25 @@ export const css = () =>
.pipe($.if(!isProduction, $.sourcemaps.write())) .pipe($.if(!isProduction, $.sourcemaps.write()))
.pipe($.if(isProduction, $.header(BANNER, { pkg: pkg }))) .pipe($.if(isProduction, $.header(BANNER, { pkg: pkg })))
.pipe($.rename({ suffix: '.min' })) .pipe($.rename({ suffix: '.min' }))
.pipe($.if(isProduction, $.rev()))
.pipe(dest(DIST + '/assets/css/')) .pipe(dest(DIST + '/assets/css/'))
.pipe($.if(isProduction, $.rev.manifest()))
.pipe($.if(isProduction, dest(DIST + '/assets/css/')))
.pipe(browser.stream()) .pipe(browser.stream())
// //
// Scripts // Scripts
// //
const jsProject = () =>
// Libraries src([
const jsLibraries = () => src('node_modules/picturefill/dist/picturefill.js') SRC + '/_assets/js/kremalicious3.js',
.pipe($.if(isProduction, $.uglify())).on('error', onError) 'node_modules/picturefill/dist/picturefill.js'
.pipe($.rename({ suffix: '.min'})) ])
.pipe($.if(isProduction, $.rev()))
.pipe(dest(DIST + '/assets/js/'))
.pipe($.if(isProduction, $.rev.manifest()))
.pipe($.if(isProduction, dest(DIST + '/assets/js/')))
// Project js
const jsProject = () => src(SRC + '/_assets/js/kremalicious3.js')
.pipe($.sourcemaps.init()) .pipe($.sourcemaps.init())
.pipe($.include()).on('error', onError) .pipe($.include()).on('error', onError)
.pipe($.if(isProduction, $.uglify())).on('error', onError) .pipe($.if(isProduction, $.uglify())).on('error', onError)
.pipe($.if(!isProduction, $.sourcemaps.write())) .pipe($.if(!isProduction, $.sourcemaps.write()))
.pipe($.if(isProduction, $.header(BANNER, { pkg: pkg }))) .pipe($.if(isProduction, $.header(BANNER, { pkg: pkg })))
.pipe($.rename({suffix: '.min'})) .pipe($.rename({suffix: '.min'}))
.pipe($.if(isProduction, $.rev()))
.pipe(dest(DIST + '/assets/js/')) .pipe(dest(DIST + '/assets/js/'))
.pipe($.if(isProduction, $.rev.manifest({
base: DIST + '/assets/js/',
merge: true
})))
.pipe($.if(isProduction, dest(DIST + '/assets/js/')))
// Service Worker js // Service Worker js
const jsSW = () => src(DIST + '/service-worker.js') const jsSW = () => src(DIST + '/service-worker.js')
@ -218,7 +203,7 @@ const jsSW = () => src(DIST + '/service-worker.js')
.pipe(dest(DIST + '/')) .pipe(dest(DIST + '/'))
// Collect all script tasks // Collect all script tasks
export const js = series(jsLibraries, jsProject, jsSW) export const js = series(jsProject, jsSW)
// //
@ -230,13 +215,7 @@ export const icons = () => src(iconset.icons)
.pipe($.filter('**/*.svg')) .pipe($.filter('**/*.svg'))
.pipe($.if(isProduction, $.imagemin({ svgoPlugins: [{ removeViewBox: false }] }))) .pipe($.if(isProduction, $.imagemin({ svgoPlugins: [{ removeViewBox: false }] })))
.pipe($.svgSprite(SPRITE)) .pipe($.svgSprite(SPRITE))
.pipe($.if(isProduction, $.rev()))
.pipe(dest(iconset.dist)) .pipe(dest(iconset.dist))
.pipe($.if(isProduction, $.rev.manifest({
base: iconset.dist,
merge: true
})))
.pipe($.if(isProduction, dest(iconset.dist)))
// //
@ -254,13 +233,7 @@ export const images = () =>
multipass: true, // svg multipass: true, // svg
svgoPlugins: [{ removeViewBox: false }] svgoPlugins: [{ removeViewBox: false }]
}))) })))
.pipe($.if(isProduction, $.rev()))
.pipe(dest(DIST + '/assets/img/')) .pipe(dest(DIST + '/assets/img/'))
.pipe($.if(isProduction, $.rev.manifest({
base: DIST + '/assets/img/',
merge: true
})))
.pipe($.if(isProduction, dest(DIST + '/assets/img/')))
// //
@ -269,8 +242,6 @@ export const images = () =>
export const fonts = () => src(SRC + '/_assets/fonts/**/*') export const fonts = () => src(SRC + '/_assets/fonts/**/*')
.pipe($.if(isProduction, $.rev())) .pipe($.if(isProduction, $.rev()))
.pipe(dest(DIST + '/assets/fonts/')) .pipe(dest(DIST + '/assets/fonts/'))
.pipe($.if(isProduction, $.rev.manifest()))
.pipe($.if(isProduction, dest(DIST + '/assets/fonts/')))
// //
@ -280,12 +251,29 @@ export const media = () => src(SRC + '/_media/**/*')
.pipe(dest(DIST + '/assets/media/')) .pipe(dest(DIST + '/assets/media/'))
//
// Revision static assets
//
export const rev = (done) => {
// globbing is slow so do everything conditionally for faster dev build
if (isProduction) {
return src(DIST + '/assets/**/*.{css,js,png,jpg,jpeg,svg,eot,ttf,woff}')
.pipe($.rev())
.pipe(dest(DIST + '/assets/'))
// output rev manifest for next replace task
.pipe($.rev.manifest())
.pipe(dest(DIST + '/assets/'))
}
done()
}
// //
// Replace all links to assets in files // Replace all links to assets in files
// from a manifest file // from a manifest file
// //
export const revReplace = (done) => { export const revReplace = (done) => {
let manifest = src(DIST + '/**/rev-manifest.json') let manifest = src(DIST + '/assets/rev-manifest.json')
// globbing is slow so do everything conditionally for faster dev build // globbing is slow so do everything conditionally for faster dev build
if (isProduction) { if (isProduction) {
@ -345,7 +333,7 @@ export const buildBanner = (done) => {
// `gulp build` is the development build // `gulp build` is the development build
// `gulp build --production` is the production build // `gulp build --production` is the production build
// //
export const build = series(buildBanner, clean, jekyll, parallel(html, css, js, images, icons, fonts, media), revReplace) export const build = series(buildBanner, clean, jekyll, parallel(html, css, js, images, icons, fonts, media), rev, revReplace)
// //
// Build site, run server, and watch for file changes // Build site, run server, and watch for file changes