Last Updated: July 25, 2019
·
67.48K
· iondrimba

Simple Gulp Copy file task

This is just a handy way of copying a file from one folder to another.
There is no goal of replacing other tools out there.
No extra lib or package needed.

gulp.task('copy', function () {
    gulp.src('./src/templates/index.html')
        .pipe(gulp.dest('./public/'));
});

2 Responses
Add your response

I use:

// copyTo.js v1
function copyTo(files, dest) {
if (typeof files == 'string') {
files = [files];
};
gulp.src(files).pipe(gulp.dest(dest));
console.log(cliDate() + ' copyTo success');
};

// cliDate.js v1
function cliDate() {
let date = new Date(),
hours = date.getHours(),
minutes = date.getMinutes(),
seconds = date.getSeconds();
hours < 10 ? hours = '0' + hours : hours;
minutes < 10 ? minutes = '0' + minutes : minutes;
seconds < 10 ? seconds = '0' + seconds : seconds;
return '[' + hours + ':' + minutes + ':' + seconds + ']';
};

over 1 year ago ·

You can also use globs to match directories and files:


gulp.task('vendor', function () {
return gulp
.src([
'./nodemodules/bootstrap/dist/',
'./nodemodules/intl/dist/
'
], { base: 'nodemodules' })
.pipe(gulp.dest('./vendor/'));
});
over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside