javascript 使用 Gulp Zip 压缩文件夹中的所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31549805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Gulp Zip to zip all the files in a folder
提问by baao
I am using gulp-zipto zip up my source files. So I have a main folder called FIFA which has other sub folders which might have more sub folders and files. In additon the FIFA folder also has files like my package.json, gulp.js and some other files. I want to basically use gulp-zip to zip up my entire project and create a folder called distribution and save the zip inside it. So this is the code i used.
我正在使用gulp-zip压缩我的源文件。所以我有一个名为 FIFA 的主文件夹,它有其他子文件夹,这些子文件夹可能包含更多子文件夹和文件。此外,FIFA 文件夹还包含诸如我的 package.json、gulp.js 和其他一些文件之类的文件。我想基本上使用 gulp-zip 来压缩我的整个项目并创建一个名为 distribution 的文件夹并将 zip 保存在其中。所以这是我使用的代码。
gulp.task('zip', function () {
return gulp.src('./*,')
.pipe(zip('test.zip'))
.pipe(gulp.dest('./distribution'));
});
The issue is that although a zip is created inside the distribution folder that zip only contains the files inside the FIFA folder, all the files inside the subfolders of FIFA are not there. So for instance if FIFA has a subfolder called ronaldo and ronaldo contains goal.js that goal.js is not in the zip. What have i done wrong? Please advice.
问题是,尽管在分发文件夹中创建了一个 zip,该 zip 仅包含 FIFA 文件夹中的文件,但 FIFA 子文件夹中的所有文件都不存在。因此,例如,如果 FIFA 有一个名为 ronaldo 的子文件夹,并且 ronaldo 包含goal.js,则goal.js 不在zip 中。我做错了什么?请指教。
回答by baao
Try it with two *
用两个试试 *
gulp.task('zip', function () {
return gulp.src('./**')
.pipe(zip('test.zip'))
.pipe(gulp.dest('./distribution'));
});
What's the difference between
*
and**
?
什么之间的区别
*
和**
?
One star means all files, no folders - too stars will be more deep and also include all the folders inside the specified folder.
一颗星意味着所有文件,没有文件夹 - 星号会更深,并且还包括指定文件夹内的所有文件夹。
And for instance if you wanted to do two stars to include all folders EXCEPT one specific folder , is that possible to do also?
例如,如果您想用两颗星来包含除一个特定文件夹之外的所有文件夹,是否也可以这样做?
You can use an exclamation mark like !./excludedDir
, pass src
as an array with the !...
as one of the values
您可以使用感叹号,例如!./excludedDir
,src
作为数组传递,作为!...
值之一