chris chris - 6 months ago 21
Node.js Question

Looking for way to copy files in gulp and rename based on parent directory

For each module I have some files that need to be copied over to the build directory, and am looking for a way to minimize the repeated code from this:



to something like this:


Obviously the above doesn't work, so is there a way to do this, or an npm that already does this?



The best way is to configure your base when sourcing files, like so:

gulp.src('./client/src/modules/**/index.js', {base: './client/src/modules'})

This tells gulp to use the modules directory as the starting point for determining relative paths.

(Also, you can use /**/*.js if you want to include all JS files...)