0
0
0x0000002F2022-03-11 23:24:12
JavaScript
0x0000002F, 2022-03-11 23:24:12

How to completely copy a directory in Gulp?

How to copy a folder exactly in Gulp? That is, in addition to the contents, there are also its child folders, also with their contents, etc. In my case, this is img/
Structure:

/
|= node_modules/
|= src/
|  |= html/
|  |  |= index.html
|  |= img/   #=> отсюда
|  |  |= gallery/
|  |  |= cards/
|  |  |= favicon.ico
|  |  |= logo.png
|  |= sass/
|= dist/
|  |= img/   #<= сюда
|  |= css/
|  |= index.html
|= package.json
|= package-lock.json
|= gulpfile.js

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
black1277, 2022-03-13
@black1277

Here is a working gulpfile.js for your project structure:

"use strict";

const {src, dest} = require("gulp");
const gulp = require("gulp");
const gulpCopy = require('gulp-copy');
const outputPath = "dist/";

var path = {
  build: {
    html: "dist/",
    images: "dist/"
  },
  src: {
    html: "src/*.html",
    images: ['src/img/**/*.*']
  }
}

function images() {
  return src(path.src.images)
    .pipe(gulpCopy(outputPath, {prefix: 1}))
    .pipe(dest(path.build.images));
}

const build = gulp.series(images);

exports.images = images;
exports.default = build;

checked at home - copies while maintaining the folder structure

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question