-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #525 from arvindr21/master
Create maintain-directory-structure-while-processing.md
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
docs/recipes/maintain-directory-structure-while-globbing.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Maintain Directory Structure while Globbing | ||
|
||
If you are planning to read a few files/folders from a directory and maintain their relative path, you need to pass `{base: '.'}` as the second argument to `gulp.src()`. | ||
|
||
|
||
For example, if you have a directory structure like | ||
|
||
![Dev setup](https://cloud.githubusercontent.com/assets/2562992/3178498/bedf75b4-ec1a-11e3-8a71-a150ad94b450.png) | ||
|
||
and want to read only a few files say | ||
|
||
```js | ||
[ 'index.html', | ||
'css/**', | ||
'js/**', | ||
'lib/**', | ||
'images/**', | ||
'plugin/**' | ||
] | ||
``` | ||
|
||
In this case, Gulp will read all the sub-folders of (_say_) `css` folder and arrange them relative to your root folder and they will no longer be the sub-folder of `css`. The output after globbing would look like | ||
|
||
![Zipped-Unzipped](https://cloud.githubusercontent.com/assets/2562992/3178614/27208c52-ec1c-11e3-852e-8bbb8e420c7f.png) | ||
|
||
If you want to maintain the structure, you need to pass `{base: '.'}` to `gulp.src()`. Like | ||
|
||
```js | ||
gulp.task('task', function () { | ||
gulp.src(['index.html', | ||
'css/**', | ||
'js/**', | ||
'lib/**', | ||
'images/**', | ||
'plugin/**' | ||
], {base: '.'}) | ||
.pipe(operation1()) | ||
.pipe(operation2()); | ||
}); | ||
``` | ||
And the input to your `operation1()` will be a folder structure like | ||
|
||
![with-base](https://cloud.githubusercontent.com/assets/2562992/3178607/053d6722-ec1c-11e3-9ba8-7ce39e1a480e.png) | ||
|