用gulp覆盖一个文件夹到另一个文件夹的所有文件

v6ylcynt  于 2022-12-08  发布在  Gulp
关注(0)|答案(1)|浏览(221)

我已经有我的方法,压缩文件的内容与gulp-minify-css在一个临时文件夹,我希望以后删除与gulp如果可能的话,但我不知道如何取代文件第一,我有:

var revReplace = require('gulp-rev-replace');  // -> this folder is not recognized

gulp.task('revrep', () => {
  return gulp.src('app/Styles/CssArqMincss')        
    .pipe(gulp.dest('app/Content/CSSArq/'));
})

我以后如何删除文件夹/Styles/CssArqMincss?谢谢

hts6caw3

hts6caw31#

要从文件夹位置删除文件,可以使用此任务并对其进行调整。

const { src, task } = require( 'gulp' );
const clean = require("gulp-clean");
const logger = require('node-color-log');

function cleanFolderTask() {
    const yourPathRoot = "pathToYourFolder"; //I would recommend using config file to store paths, such as : config.path.artifact.root;
    logger.color('yellow').log(`Cleaning ${yourPathRoot}`);

    return src(yourPathRoot ,{allowEmpty: true},{read: false}).pipe(clean({force:true}));
};

const cleanFolderTask= task('clean:folder', cleanFolderTask);
exports.cleanFolderTask= cleanFolderTask;

要从一个文件夹复制到另一个文件夹,我还将使用上一个任务首先清理目标,然后:

const { src, dest, task } = require( 'gulp');
const logger = require('node-color-log');

function copyFilesTask(callback) {
    let filesLoc = "path/to/your/files"; 
    let filesDest = "path/to/destination"; // I would recommend using config file to store paths, such as : config.path.artifact.files and config.path.solution.files;

    logger.color('yellow').log(`Copy ${filesDest }`);

    src(`${filesLoc}/**/*`)
        .pipe(dest(filesDest), 
        callback());
};

const copyFiles = task('copy:files', copyFilesTask);
exports.copyFiles = copyFiles;

相关问题