Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overwrite file in gulp stream

Tags:

gulp

I have following directory structure:

common
-services
--service1.js
--service2.js
-app
--gulpfile.js
--src
---services
----service1.js
----service3.js

I want to made gulp task that will take all files from common directory, take files from app directory and replace all files with same filenames in original stream. After that I will concat it and write to other directory. I tried this:

var gulp = require('gulp'),
    merge = require('gulp-merge'),
    concat = require('gulp-concat');
 gulp.task('templates', function () {
  return merge(
    gulp.src(['../common/**/*.js']),
    gulp.src(['src/**/*.js'])
  )
    .pipe(concat('app.js'))
    .pipe(gulp.dest('build/js'));
});

I expected to got content of common/services/service2.js, app/src/services/service1.js, app/src/services/service3.js in dest/app.js. But instead I've got content of all files. I tried to change cwd or base of gulp.src, but it has no effect. I know that I can write this stream to tmp directory, and after that get files from it, but it seems not really like gulp-style solution. So how can I overwrite files with same file names in streams?

like image 490
Heymdall Avatar asked Apr 24 '26 05:04

Heymdall


1 Answers

Ok, i can't find any existing solution for that, so I write my own gulp plugin: gulp-unique-files.

like image 128
Heymdall Avatar answered Apr 26 '26 16:04

Heymdall