gpt4 book ai didi

node.js - 使用 gulp 选择和移动目录及其文件

转载 作者:IT老高 更新时间:2023-10-28 21:47:45 27 4
gpt4 key购买 nike

我目前正在使用 gulp 调用一个 bash 脚本来清理我的 dist/ 目录并将适当的文件移动到干净的目录中。我希望使用 gulp 完成此操作,因为我不确定该脚本是否可以在非 *nix 文件系统上运行。
到目前为止,我正在使用 gulp-clean 模块来清理 dist/ 目录,但是当我尝试将所需的目录及其文件移动到 dist 文件夹时,目录是空的。

var gulp = require('gulp'),
clean = require('gulp-clean');

gulp.task('clean', function(){
return gulp.src(['dist/*'], {read:false})
.pipe(clean());
});

gulp.task('move',['clean'], function(){
gulp.src(['_locales', 'icons', 'src/page_action', 'manifest.json'])
.pipe(gulp.dest('dist'));
});

gulp.task('dist', ['move']);

调用 gulp dist 会导致 dist/ 目录被正确的目录填充,但它们都是空的

$ ls dist/*
dist/manifest.json

dist/_locales:

dist/icons:

dist/page_action:

如何将目录及其内容复制到 dist/ 文件夹?

最佳答案

您需要包含 base option到 src,它将以您想要的方式保留文件结构:

var filesToMove = [
'./_locales/**/*.*',
'./icons/**/*.*',
'./src/page_action/**/*.*',
'./manifest.json'
];

gulp.task('move',['clean'], function(){
// the base option sets the relative root for the set of files,
// preserving the folder structure
gulp.src(filesToMove, { base: './' })
.pipe(gulp.dest('dist'));
});

此外,如果您在项目的根目录中拥有所有这些源文件,您可能会遇到麻烦。

如果可以的话,我建议您使用单个 src/ 文件夹并将您的应用程序特定文件所有移到该文件夹​​中。这使得维护更容易向前推进,并防止您的构建特定文件与您的应用程序特定文件混淆。

如果您这样做,那么只需将上面示例中所有出现的 ./ 替换为 src/

关于node.js - 使用 gulp 选择和移动目录及其文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21546931/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com