gulp中仅定位文件夹的内容

时间:2022-10-30 00:27:39

I'm using Gulp to compile a project. I'm also using gulp-zip to zip a bunch of files.

我正在使用Gulp编译项目。我也使用gulp-zip来压缩一堆文件。

I want to zip up all the files in the "dist" folder, so I'm using this:

我想压缩“dist”文件夹中的所有文件,所以我使用这个:

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:

这会按以下方式将文件编译为zip:

  • dist
    • file.css
    • another.js
    • folder
      • file.js
  • dist file.css another.js文件夹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?

没有dist文件夹。有没有办法使用不同的src路径?

Thanks for your help.

谢谢你的帮助。

3 个解决方案

#1


5  

gulp-zip doesn't honor base. See for some background:

gulp-zip不尊重基地。请参阅以下内容:

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'));
});

#2


0  

Ok, try:

return gulp.src(thesrc, {base: 'dist'})

#3


0  

For me, following did work:

对我来说,以下工作:

// Taking everything from src and doc dirs
return gulp.src(['src/**/*', 'doc/**/*'], { base: __dirname })
  .pipe(zip('dist.zip'))
  .pipe(gulp.dest('dist'));

#1


5  

gulp-zip doesn't honor base. See for some background:

gulp-zip不尊重基地。请参阅以下内容:

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'));
});

#2


0  

Ok, try:

return gulp.src(thesrc, {base: 'dist'})

#3


0  

For me, following did work:

对我来说,以下工作:

// Taking everything from src and doc dirs
return gulp.src(['src/**/*', 'doc/**/*'], { base: __dirname })
  .pipe(zip('dist.zip'))
  .pipe(gulp.dest('dist'));