Answer the question
In order to leave comments, you need to log in
How to determine the directory through the task?
There is a folder with resources (resources) where I store static files favicons, robots.txt and other configuration files. I also have several directories there. So directories with their contents should be copied to the directory dist/assets
, and files that lie outside these directories (in the resourses root) should be copied to dist
. I managed to implement it in the way below.
gulp.task("copy", function () {
gulp.src(['src/resources/**', '!src/resources/{{fonts,files},{fonts,files}/**}'])
.pipe(gulp.dest("dist"))
gulp.src("src/resources/{fonts,files}/**")
.pipe(gulp.dest("dist/assets"))
});
Answer the question
In order to leave comments, you need to log in
Separate files and folders using fs.lstatSync(name).isDirectory() and copy what and where you need.
Something like this:
const fs = require('fs');
gulp.task('copy', function(done) {
const allFiles = fs.readdirSync('./');
const allStats = allFiles.reduce((stats, name) => {
fs.lstatSync(name).isDirectory() ? stats.dirs.push(name) : stats.files.push(name);
return stats;
}, {files: [], dirs: []});
gulp.src(allStats.files)
.pipe(gulp.dest("dist"));
gulp.src(allStats.dirs)
.pipe(gulp.dest("dist/assets"));
done();
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question