@ideasonpurpose/gulp-task-copy
v0.1.2
Published
A gulp 4 task for copying static assets
Downloads
2
Readme
Installation
$ yarn add @ideasonpurpose/gulp-task-copy
or
$ npm install @ideasonpurpose/gulp-task-copy
Usage
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.src
srcOptions
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-src
except forsince
.- srcOptions.since
To use incremental builds, set the value ofsince
totrue
. This will be replaced withgulp.lastRun
in the generated function. (Thegulp
instance will also need to be included, see gulp below)
- srcOptions.since
dest
The output path to be passed togulp.dest
Defaults todist
Passed directly togulp.dest
gulp
The current gulp instance. Required whensrcOptions.since
istrue
or when using thewatch
helper 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)`
};