@ideasonpurpose/gulp-task-copy v0.1.2
Installation
$ yarn add @ideasonpurpose/gulp-task-copy
or
$ npm install @ideasonpurpose/gulp-task-copyUsage
This module is a factory function which returns a pre-configured copy task for gulp 4.
Basic
Call the create method directly on the import. In most cases, just trust the defaults and go:
// Call `create` on the require to initialize a new task
const copy = require("@ideasonpurpose/gulp-task-copy").create();
// Export to make the task publicly callable
exports.copy = copy;Options
const defaults = {
src: ["**/*", "!webpack.config.js", "!{images,js,sass}/**/*"],
srcOptions: { cwd: "./src", nodir: true },
dest: "./dist"
};The create method accepts one configuration object. This module accepts four properties:
src
A glob string or array of glob-strings. Defaults to["**/*", "!webpack.config.js", "!{images,js,sass}/**/*"Passed directly togulp.srcsrcOptions
An object containing any options recognized by gulp.src string or array of glob-strings. Defaults to{ cwd: "./src", nodir: true }. All options are passed directly togulp-srcexcept forsince.- srcOptions.since
To use incremental builds, set the value ofsincetotrue. This will be replaced withgulp.lastRunin the generated function. (Thegulpinstance will also need to be included, see gulp below)
- srcOptions.since
dest
The output path to be passed togulp.destDefaults todistPassed directly togulp.destgulp
The current gulp instance. Required whensrcOptions.sinceistrueor when using thewatchhelper method.
Incremental Builds
If srcOptions includes since: true, a gulp instance must be passed into the task for the incremental build checks to work correctly. Something like this:
const copy = require("@ideasonpurpose/gulp-task-copy").create({
src: ["**/*", "!webpack.config.js", "!{images,js,sass}/**/*"],
srcOptions: { since: true },
dest: "dist",
gulp // or `gulp: gulp`, same thing.
});Incremental builds may prevent newly added files from being processed. If the modification dates of the new files are before the task's last-run timestamp, the new files will not be processed. Either restart the watch or touch the files to be added.
Watch helper
Very frequently, gulp watch globs are identical to the source globs for a given task. To reduce repetition, the generated task includes a helper method which calls gulp.watch with default arguments. This makes writing watch tasks very concise and easy to maintain.
const copy = require("@ideasonpurpose/gulp-task-copy").create({ gulp });
const watch = () => {
copy.watch(); // calls `gulp.watch(src, {cwd: srcOptions.cwd}, copy)`
};