gulp.src base option: preserving nested directories during gulp.dest
0 reputation · 26 Sept 2023, 17:10 UTC
0 reputation · 26 Sept 2023, 17:10 UTC
In Gulp 4.x, the gulp.src stream attaches a base path to each Vinyl file. When the base option is omitted, Gulp defaults to the glob stem before the first wildcard. gulp.dest writes files by appending file.relative to the destination directory, so the final output hierarchy depends entirely on file.base.
Because gulp.dest overwrites existing files without prompting, developers often rely on an explicit base to ensure that nested source folders are preserved and to avoid accidental data loss during a backup‑restore cycle. However, the exact derivation of base when complex globs (e.g., braces, extglob patterns) are used remains unclear, and there is no documented fallback for restoring stripped top‑level directories after a failed build.
Key uncertainty: how does Gulp determine the base path for files matched by globs that contain nested patterns, and can this behavior be reliably controlled to support automated backup and restoration of the full source tree?
file.base and file.relative for every file in a complex multi‑glob pipeline to verify the intended output structure?base is implicitly derived?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.