New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't exclude directories using src glob #165

Closed
aaronbushnell opened this Issue Jan 16, 2014 · 28 comments

Comments

Projects
None yet
@aaronbushnell
Copy link

aaronbushnell commented Jan 16, 2014

I can't exclude a directory from being copied over when using a src glob. Here's my task:

gulp.task('copy', function() {
    return gulp.src(['app/**', '!app/_tmp/**'])
        .pipe(gulp.dest('dist'));
});

Gulp copies over app/**, but app/_tmp/ is still being copied.

Expected:

+ app/
  + tmp/
      file1
      file2
  + css/
      styles.css
  + js/
      app.js
+ dist/
  + css/
      styles.css
  + js/
      app.js

Gulp output:

+ app/
  + tmp/
      file1
      file2
  + css/
      styles.css
  + js/
      app.js
+ dist/
  + tmp/
  + css/
      styles.css
  + js/
      app.js

Update: Clarified that the dist/_tmp/ directory does not contain any files

@stryju

This comment has been minimized.

Copy link
Contributor

stryju commented Jan 16, 2014

so tmp or _tmp ?

@sindresorhus

This comment has been minimized.

Copy link
Contributor

sindresorhus commented Jan 16, 2014

You're globbing for files, if you want to ignore the dir you need to: gulp.src(['app/**', '!app/_tmp/'])

@aaronbushnell

This comment has been minimized.

Copy link

aaronbushnell commented Jan 16, 2014

@sindresorhus No dice. Now the dist/_tmp/ directory has the files from app/_tmp/ inside it.

@aaronbushnell

This comment has been minimized.

Copy link

aaronbushnell commented Jan 17, 2014

Just an update: I updated to gulp 3.4.0 and am still having the same issue.

@stryju

This comment has been minimized.

Copy link
Contributor

stryju commented Jan 17, 2014

@aaronbushnell can you create a repo so we can clone it and work on the same dir structure? :)

@aaronbushnell

This comment has been minimized.

@gfloyd

This comment has been minimized.

Copy link

gfloyd commented Jan 17, 2014

The way I've made this work is to exclude the directory and the contents like so: gulp.src(['app/**', '!app/_tmp', '!app/_tmp/**'])

@aaronbushnell

This comment has been minimized.

Copy link

aaronbushnell commented Jan 17, 2014

@gfloyd Hm, doing that still copied over the tmp/ directory to dist/ (it was empty though).

@stryju

This comment has been minimized.

Copy link
Contributor

stryju commented Jan 17, 2014

@aaronbushnell

gulp.src(['app/**', '!app/{_tmp,_tmp/**}'])

why?

  • !app/_tmp would match only the folder, but not any file within it - since it's not a globbing expression (a bug?)
  • !app/_tmp/** would match the files IN the _tmp folder, but not the folder itself, so the empty folder would be created

using the !app/{_tmp,_tmp/**} pattern uses a pattern to combine the both requirements and says:

give me all the dirs/files in app folder EXCEPT for _tmp folder content and the _tmp directory itself

:-)

@stryju

This comment has been minimized.

Copy link
Contributor

stryju commented Jan 17, 2014

seems like that it is not clear - maybe we should create a recipe with that?

/cc @contra

@aaronbushnell

This comment has been minimized.

Copy link

aaronbushnell commented Jan 17, 2014

@stryju That worked perfectly! Thanks for the help. Will this be simplified in the future or should I plan on always writing exclusions like this?

@stryju

This comment has been minimized.

Copy link
Contributor

stryju commented Jan 17, 2014

more of a question @ https://github.com/isaacs/minimatch :-)


issue resolved? ;-)

@aaronbushnell

This comment has been minimized.

Copy link

aaronbushnell commented Jan 17, 2014

Resolved. I'll bring the issue there. Thanks, all!

@stryju

This comment has been minimized.

Copy link
Contributor

stryju commented Jan 17, 2014

happy to help :)

@timrwood

This comment has been minimized.

Copy link

timrwood commented Jan 17, 2014

It can be golfed further to !app/_tmp{,/**} so you don't need to repeat the directory name.

@chovy

This comment has been minimized.

Copy link

chovy commented Oct 15, 2014

Does not work for me:

  gulp.src([
    'client/public/**/*',
    '!client/public/{vendor, vendor/**}',
    ], { base: './' })
    .pipe(gulp.dest('./dist'));

I'm still getting a populated vendor directory.

@heikki

This comment has been minimized.

Copy link
Contributor

heikki commented Oct 15, 2014

@chovy You have a space there that messes things up: {vendor, vendor/**}.

@ktstowell

This comment has been minimized.

Copy link

ktstowell commented Jan 29, 2015

['!node_modules', '!node_modules/**', './**'] Worked for me, though I do like @aaronbushnell 's proposition in isaacs/minimatch#25

@alexpi

This comment has been minimized.

Copy link

alexpi commented Jul 27, 2015

I want to match everything except bower_components and anything inside.
So, I used the following code as suggested, but this still matches any folder that has .html files inside, together with those files.

return gulp.src([
        'src/*',
        '!src/**/*.html',
        '!src/bower_components{,/**}'
    ]

Any suggestions?

@stryju

This comment has been minimized.

Copy link
Contributor

stryju commented Jul 27, 2015

@alexpi this pattern will include the folders containing the html files, but should exclude the html files themselves - is that the case?

@alexpi

This comment has been minimized.

Copy link

alexpi commented Jul 27, 2015

Sorry! There was no issue after all, another Gulp task was the culprit. The code works as expected.

@hermeslm

This comment has been minimized.

Copy link

hermeslm commented Jul 31, 2015

Thanks to gfloyd, that solution works.

@zeshanshani

This comment has been minimized.

Copy link

zeshanshani commented Mar 24, 2016

Thank you, @ktstowell, your solution worked really well. I'm working with Gulp Zip. It was really cumbersome to exclude a few folders/files and keep everything else including the project tree as it is.

@stryju Thank you for your solution of using !{_tmp,_tmp/**} method. I was using !(.gitignore,.sftp-config.json) to exclude a few files, but that didn't work.

Here's my code:

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

gulp.task( 'zip', function() {

  return gulp.src( [
    '!{.gitignore,sftp-config.json}',
    '!node_modules', '!node_modules/**',
    '!dist', '!dist/**',
    '!assets/bower_components', '!assets/bower_components/**',
    './**',
  ] )
    .pipe( zip('archive.zip') )
    .pipe( gulp.dest( 'dist' ) );

});
@acauamontiel

This comment has been minimized.

Copy link

acauamontiel commented Mar 30, 2016

This works well for me:

gulp.src(['app/**', '!app/_tmp{,/**/*}'])
@vmasto

This comment has been minimized.

Copy link

vmasto commented Apr 10, 2016

Just as a note, I used to use:

gulp.src([
  '!node_modules{,/**}',
  '!dist{,/**}'
])

But then converting it to:

gulp.src([
  '!node_modules',
  '!node_modules/**',
  '!dist',
  '!dist/**'
])

Shaved off at least 3 whole seconds from my task.
Just a heads up, you might want to test your task if you care about performance; it would appear the dir{**} notation is really slow.

@npineda

This comment has been minimized.

Copy link

npineda commented Jun 4, 2016

I was calling a folder above and copying all it's content expect from the folder I was currently inside(called "deploy"). This worked for me - gulp.src(['../**/*','!../deploy','!../deploy/**']).

@maruilian11 maruilian11 referenced this issue Dec 26, 2016

Merged

add design-system v2.0.2 with npm auto-update #8358

16 of 19 tasks complete
@kennycrosby

This comment has been minimized.

Copy link

kennycrosby commented Apr 20, 2017

Read through this thread and tried a bunch of things but still directories are copying over. I want to exclude ALL of /src but src/images/sub-directory ends up getting copied albeit empty.

gulp.src([
    'dev/wordpress/**/*',
    'dev/wordpress/**/.*',
    '!dev/wordpress/wp-content/themes/lucidworks/src{,/**/*}',
  ])
    .pipe(gulp.dest(myDest));

I end up with:

src/images/sub-directory/(empty)
src/fonts/(empty)

Using gulp babel. Any ideas?

@Triloworld

This comment has been minimized.

Copy link

Triloworld commented Jan 17, 2018

There is one line solution. It is great when glob need to be apply relative:

@import "../../!(web)/**/*.scss";

It import:

  • ../../name/x.scss
  • ../../name/name/x.scss
  • ../../name/web/x.scss
  • ../../name/web/web/x.scss

Don't import:

  • ../../web/x.scss
  • ../../web/name/x.scss

So it basically work as one level directory exclude.
It can be even something like this:

  • ../../!(web)/!(web)/**/.scss

Important: It won't work if added AFTER "**".
Like this one: ../ ../ ** / !(web) / *.scss (how to choose on what level directory exclude when multilevel are included?)

@gulpjs gulpjs locked and limited conversation to collaborators Jan 17, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.