gulp-simpletask
v1.0.5
Published
A slightly cleaner way to use gulp tasks, with plumber and notify.
Downloads
19
Maintainers
Readme
gulp-simpletask
A simpler way to use gulp, with some default error handling and notifications.
task( name, file, action )
- name - The name of the task, used to identify the task.
- file - An object describing the
src
,dst
and optionalwatch
paths. - action - A function that returns an array of what is normally fed into
pipe(...)
,
Here's an simple example:
var task = require('gulp-simpletask'),
sourcemaps = require('gulp-sourcemaps'),
autoprefixer = require('gulp-autoprefixer'),
sass = require('gulp-sass');
task('scss',
{
src: [
'src/css/theme.scss'
],
dst: 'dist/css/',
watch: 'src/css/**/*.scss'
},
() => [
sourcemaps.init(),
sass({
sourceComments: false,
outputStyle: 'compressed',
precision: 4
}),
sourcemaps.write('.')
]);
All you need to do is simply call gulp
on the command line, it automatically will use the tasks defined as the default set.
Each task is backed by gulp-plumber
and gulp-notify
to handle and inform you of errors.
Its important to note that each task automatically watches the with gulp-watch
. If the watch
parameter is not given, the src
parameter is used.
Hey, what if I just want to copy files to the destination?
This is what I used in one of my projects. Simply don't specify the action
function.
task('extra',
{
src: [
'src/**/*',
'!src/!(js-lib)/**/*.js', // Ignore js, unless in the js-lib folder
'!src/**/*.{html,scss,png,jpg,jpeg,gif,svg}', // Ignore all other files
],
dst: 'dist/'
});
But wait, how do I handle events?
Glad you asked, there is a way to be a bit more explicit about tasks.
For example with gulp-rollup
and its bundle
event.
Take note of the file
argument, this is the parameter specified with src
, dst
, and watch
,
var caches = {};
task('js',
{
src: [
'src/js/index.js',
],
dst: 'dist/js/',
watch: 'src/js/**/*.js'
},
file => [
// ... Stuff before
{
// Pipe call
pipe: rollup({
entry: file.src,
// ... Config stuff
}),
// On events
on: {
bundle: (bundle, name) => {
caches[name] = bundle;
}
}
},
// ... Stuff after
]);
Ok, thats pretty neat... but how do I do X?
Well at this point its probably best to just use normal gulp as doing more elaborate things defeats the utility of this package.