Intro
Re-usable Gulp 4 tasks for Joinbox projects that cover
the following file types:
- scripts
- styles
- templates
- images (TBD)
The tasks support:
- source maps
- notifications
- minification
- browser sync
- cache busting (TBD)
- etc.
Available Tasks
BuildTaskBuilder exposes the following tasks when using the default config:
General
gulp
: First clears your destination directory, then calls dev
, then watch
and then starts up
a browserSync webservergulp prod
: Clears destination, then creates production filesgulp serve
: Just boots up and runs the server; changes won't be watched (as no watch tasks are
started)gulp clean
: Removes the destination folder
JS
jsDev
: Clears JS folder in destination, converts JS files, then haltsjsWatch
: Only watches JS files (triggers on change)js
: jsDev
then jsWatch
jsProd
: Clears JS folder in destination, converts and minifies files for production
CSS
cssDev
: Clears CSS folder in destination, converts css files, then haltscssWatch
: Only watches CSS files (triggers on change)css
: cssDev
then cssWatch
cssProd
: Clears CSS folder in destination, converts and minifies files for production
HTML
htmlDev
: Clears HTML folder in destination, copies all HTML fileshtmlWatch
: Only watches HTML files (triggers on change)html
: htmlDev
then htmlWatch
htmlProd
: Clears HTML folder in destination, converts and minifies files for production
Settings
See default settings. Can be changed with setConfig
(see
below).
Setup
-
Create a new folder
-
Install gulp 4 and build-task locally, gulp-cli globally:
npm i -D @joinbox/build-task gulp@4
npm i -g gulpjs/gulp-cli
-
Add a gulpfile.js …
touch gulpfile.js
-
Either use the default config …
const BuildTask = require('@joinbox/build-task');
const builder = new BuildTask();
module.exports = builder.createTasks();
-
… or adjust it to match your own setup:
const BuildTask = require('@joinbox/build-task');
const builder = new BuildTask();
builder.setConfig('paths.css.entryPoints', ['styles.scss']);
builder.setConfig('paths.js.technologies', ['react']);
builder.setConfig('supportedBrowsers', ['>1%']);
builder.setConfig('server', false);
const imageSources = 'www/src/**/*.png';
function imgDev() {
return gulp.src(imageSources)
.pipe(gulp.dest('www/dist'));
}
function imgWatch() {
return gulp.watch(imageSources, imgDev);
}
builder.tasks.set('imgWatch', imgWatch);
builder.tasks.set('imgDev', imgDev);
builder.devTasks.push(imgDev);
builder.watchTasks.push(imgWatch);
module.exports = builder.createTasks();
-
Run your tasks
As you added your own imgWatch
and imgDev
functions to the gulp task, they will now be part
of the default gulp task and therefore be invoked when executing:
gulp
Tests
There are a few automated tests, run them with npm test
. To test the implementation, call the gulp
files in the test
folder:
cd test && gulp -f gulpfile.default.js