A
A
Alexey Dubrovin2021-06-09 10:20:18
gulp.js
Alexey Dubrovin, 2021-06-09 10:20:18

How to make dynamic generation for dest depending on src?

The layout is developed in a modular way, separating each logical block into a folder . It is necessary that during the operation of any task that looks at files by type
component/#компоненты#/"файлы"

function html(){
  return gulp.src( './component/*/*.html' )
          .pipe( include() )  //Совершили какое-то действие... минификация, компиляция, всё что угодно
          .pipe( gulp.dest('build/#Путь откуда взяли#') );  //Как получить путь, откуда взят файл?
}

By default, it drops all files into 1 folder.
It is necessary that modularity be preserved in the working structure.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Dubrovin, 2021-06-09
@alekcena

Solved the problem, found a module that returns an array with directories.

function generateFolderMap(fileDir){
    let fs = require('fs');
    let result = fs.readdirSync(fileDir, { withFileTypes: true })
        .filter(a => a.isDirectory())
        .map(a => a.name);
    return result;
}
module.exports = generateFolderMap;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question