0

i am trying do make a gulp task to compile a lot of modules at same time. My paths are...

packages/module1/src/file.js
packages/module2/src/file.js
packages/module2/src/sufolder/subfile.js

What i need to acomplish wirh gulp is:

packages/module1/dist/file.js
packages/module2/dist/file.js
packages/module2/dist/sufolder/subfile.js

My src looks like this: Gulp.src(./packages/*/src/**/*.js)

This is getting the right files, but i cannot get Gulp.dest() to te right place!

EDIT

After more searching, i got this working using gulp-folders and a simple map.

var packagesFolder = './packages';

gulp.task('packages:jsx', folders(packagesFolder, function (folder) {
    return gulp.src(path.join(packagesFolder, folder, '/src/**/*.jsx'))
        .pipe(debug({ title: 'packages:jsx' }))
        .pipe(sourcemaps.init())
        .pipe(babel({
            presets: ['es2015', 'react'],
            plugins: ['syntax-async-generators', 'transform-regenerator', 'transform-class-properties']
        }))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(path.join(packagesFolder, folder, '/dist')))
        .on('error', gutil.log);
}));
Felipe Deitos
  • 164
  • 1
  • 1
  • 11
  • Possible duplicate of [Gulp.js - Use path from gulp.src() in gulp.dest()](http://stackoverflow.com/questions/22240977/gulp-js-use-path-from-gulp-src-in-gulp-dest) – Sven Schoenung Mar 03 '17 at 16:21
  • Actually, the solutions in that question don't work if you have subfolders, gulp-rename cannot modify the path. At least i could not accomplish using only rename.... I'll be posting the solution i found i next minutes. Cheers. – Felipe Deitos Mar 03 '17 at 17:10
  • `gulp-rename` **can** modify the path. It's right there in the [usage example](https://www.npmjs.com/package/gulp-rename#usage). – Sven Schoenung Mar 03 '17 at 17:15
  • Ok, but pretend you have a 'src' folder to each package (lots of packages), so you need to loop the packages, 'src' is in the middle of the path now, how do you remove it and add 'dist' folder in its place? – Felipe Deitos Mar 03 '17 at 17:18
  • [replace()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) – Sven Schoenung Mar 03 '17 at 17:25
  • Yeah we thought about just replacing the string, now it will probably work for us, but we fear that in the future it may cause some problem. Anyway, thanks for all the answers. – Felipe Deitos Mar 03 '17 at 17:29

0 Answers0