只在gulp中定位文件夹的内容 [英] Target only the contents of a folder in gulp
问题描述
我想压缩dist文件夹中的所有文件,因此我使用这个:
var thesrc:['dist / ** / *'];
gulp.task('createMainZip',['createPluginZip'],function(){
return gulp.src(thesrc)
.pipe(zip('main_files.zip'))
.pipe(gulp.dest('compiled'));
});
以下列方式将文件编译为zip:
- dist
- file.css
- another.js
- 文件夹
- file.js
li>
然而,我想这样:
- file.css
- another.js
- 文件夹
- file.js
没有dist文件夹。有没有办法使用不同的src路径来做到这一点?
感谢您的帮助。 方案
gulp-zip不尊重
base
。请参阅以下背景:
- https://github.com/sindresorhus/gulp-zip/issues/10
- https://github.com/sindresorhus/gulp-zip/pull/11
- < a href =https://github.com/sindresorhus/gulp-zip/blob/master/index.js#L30 =noreferrer> https://github.com/sindresorhus/gulp-zip/blob/ master / index.js#L30
现在,您可以做这样的事情(无可否认):
var gulp = require('gulp');
var zip = require('gulp-zip');
var thesrc = ['** / *'];
gulp.task('createMainZip',function(){
return gulp.src(thesrc,{cwd:__dirname +/ dist})
.pipe(zip('main_files。 zip'))
.pipe(gulp.dest('compiled'));
});
I'm using Gulp to compile a project. I'm also using gulp-zip to zip a bunch of files.
I want to zip up all the files in the "dist" folder, so I'm using this:
var thesrc: ['dist/**/*']; gulp.task('createMainZip', ['createPluginZip'], function () { return gulp.src(thesrc) .pipe(zip('main_files.zip')) .pipe(gulp.dest('compiled')); });
This compiles the files to a zip in the following way:
- dist
- file.css
- another.js
- folder
- file.js
However, I want it like this:
- file.css
- another.js
- folder
- file.js
Without the dist folder. Is there a way to do this using a different src path?
Thanks for your help.
解决方案gulp-zip doesn't honor
base
. See for some background:- https://github.com/sindresorhus/gulp-zip/issues/10
- https://github.com/sindresorhus/gulp-zip/pull/11
- https://github.com/sindresorhus/gulp-zip/blob/master/index.js#L30
Now, you can do something like that (admittedly ugly):
var gulp = require('gulp'); var zip = require('gulp-zip'); var thesrc = ['**/*']; gulp.task('createMainZip', function () { return gulp.src(thesrc, {cwd: __dirname + "/dist"}) .pipe(zip('main_files.zip')) .pipe(gulp.dest('compiled')); });
这篇关于只在gulp中定位文件夹的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!