From cc9519a6b7404bf1d0ddb607f71232bba6971b95 Mon Sep 17 00:00:00 2001 From: "Jocelyn Badgley (Twipped)" Date: Thu, 5 Mar 2020 19:42:14 -0800 Subject: [PATCH] =?UTF-8?q?Add=20watch=20tasks=20for=20smaller=20bits,=20s?= =?UTF-8?q?o=20we=E2=80=99re=20not=20building=20the=20entire=20site=20for?= =?UTF-8?q?=20css=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/index.js | 24 ++++++++++++++++++++++++ gulp/index.js | 23 +++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/build/index.js b/build/index.js index 313bfb1..80a8c3c 100644 --- a/build/index.js +++ b/build/index.js @@ -68,3 +68,27 @@ exports.everything = function (prod = false) { fn.displayName = prod ? 'buildForProd' : 'build'; return fn; }; + + +exports.task = function (action, prod = false) { + const fn = async () => { + const tasks = await { + scss, + favicon, + svg, + scripts, + }[action](prod); + + if (!tasks.length) return; + + await fs.ensureDir(resolve('dist')); + const cache = new Cache({ prod }); + await cache.load(); + await evaluate(tasks, cache); + await evaluate(tasks.flat(), cache); + await cache.save(); + }; + + fn.displayName = prod ? action + 'ForProd' : action; + return fn; +}; diff --git a/gulp/index.js b/gulp/index.js index c733636..3f09be3 100644 --- a/gulp/index.js +++ b/gulp/index.js @@ -8,6 +8,11 @@ var build = require('../build'); const devBuildTask = build.everything(); const prodBuildTask = build.everything(true); +const scss = exports.scss = build.task('scss'); +const favicon = exports.favicon = build.task('favicon'); +const svg = exports.svg = build.task('svg'); +const scripts = exports.scripts = build.task('scripts'); + var cleanTask = require('./clean'); exports.clean = cleanTask; @@ -39,10 +44,24 @@ function watcher () { 'public/**/*', 'posts/**/*', 'templates/*.{md,hbs,html}', - 'scss/*.scss', - 'js/*.js', ], devBuildTask); + watch([ + 'scss/*.scss', + ], scss); + + watch([ + 'js/*.js', + ], scripts); + + watch([ + 'svg/**/*.svg', + ], svg); + + watch([ + 'favicon.png', + ], favicon); + server(); }