Whilst this script is using gulp 4.0.0-alpha.2, I suspect that the script was originally written for 3.x.
I have a gulp script that I inherited which has the following task present:
pump([
gulp.src(['app\\images\\**\\*.*']),
gulp.dest('.dev\\images')
] , done);
(The values passed into .src
and .dest
were originally retrieved from elsewhere but there doesn't appear to be any code that modifies them)
The app\images
folder contains an icons
sub-folder which contains multiple files, the result of the gulp script is:
- On
4.0.0-alpha.2
, these files get placed in.dev\images\icons
- On
4.0.2
, these files get paced in.dev\images\app\images\icons
It appears that the two full paths get concatenated now, whereas previously only the relative paths from the glob (i.e. when app\images\**\*.*
found app\images\icons\icon1.png
it returned icons\icon1.png
).
Passing base
into the options when calling src
appears to resolve this:
pump([
gulp.src(['app\\images\\**\\*.*'], { base: 'app\\images\\' }),
gulp.dest('.dev\\images\\')
] , done);
This doesn't solve cases where an array of paths with disparate base paths is passed, e.g:
['app\\styles\brand\**\*.*', 'app\\brands\icons\icons.data.svg.css']
It also seems likely that there's a more generic solution available that doesn't require me to update every invocation of src
, so....
How can I obtain the same behaviour using Gulp 4.0, where only the glob onwards, or the name of the file is used when writing to the destination?
Minimal repro gulpfile.js
:
'use strict';
const gulp = require('gulp');
exports.build = function()
{
return gulp.src(['app\\images\\**\\*.*'])
.pipe(gulp.dest('.dev\\images'));
}
And package.json
:
{
"name": "test-web",
"version": "1.0.0",
"description": "Test Project",
"main": "gulpfile.js",
"scripts": {
"build": "gulp build"
},
"author": "Me",
"license": "ISC",
"devDependencies": {
"gulp": "^4.0.2"
}
}
There are files under app\images\android
and app\images\apple
(2 in each)
Result with gulp@4.0.0-alpha.2
(expected/desired):
- .dev\images\android\1.png
- .dev\images\android\2.png
- .dev\images\apple\1.png
- .dev\images\apple\2.png
Result with gulp@v4.0.2
(un-expected):
- .dev\images\app\images\android\1.png
- .dev\images\app\images\android\2.png
- .dev\images\app\images\apple\1.png
- .dev\images\app\images\apple\2.png