只在gulp中定位文件夹的内容 [英] Target only the contents of a folder in gulp

查看:109
本文介绍了只在gulp中定位文件夹的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我想压缩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 。请参阅以下背景:



    现在,您可以做这样的事情(无可否认):

      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:

    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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆