Copy files and directories with gulp.js


I am using the gulp.js task manager in my AngularJS and Django project.

Due to the configuration of my git repository, the static directory, called assets is not controlled, so I have a directory, sources , where the source files are.

I am doing a task to copy I am files (initially unprocessed, compress, etc.) to the assets folder doing this:

// Configuración
var config = {
  sourcesDir: './sources',
  bowerDir: './bower_components'

// tarea fuentes
gulp.task('fuentes', function(){
  gulp.src([config.sourcesDir + '/css/styles.css'])

That is, a single file moves from the origin src to destination dest without problems.

My problem is that I'm doing the services of angular with the same Django structure and I have several directories with one or more files inside a javascript folder, like this:

├── auth
├── cmi.js
├── indicadores
│   ├── encuestas
│   └── productividad
├── inecap
└── metas

Question: How do I set my fuentes task to copy the js files and the source structure [config.sourcesDir + '/js'] to destination ./assets/js ?

asked by toledano 09.02.2016 в 03:08

1 answer


You can try this:

For everyone:

gulp.task('copy', function () {
        gulp.src([config.sourcesDir + '/js'+'/**/*'])

For only the type indicated (example with .js):

gulp.task('copy', function () {
            gulp.src([config.sourcesDir + '/js'+'/**/*.js'])


  • js / ** / *. js matches files ending in .js inside of the js directory and within all sub-folders of this.

  • js / suDirectorySource / exactly.js exactly matches the file.

  • js / suDirectorySource / *. js matches files ending in .js inside from the js/suDirectorioSource folder.

  • ! js / suDirectorySource / excluir.js excludes the file excluir.js with the use of !

  • Source /*.+ (js | css) matches files that end in .js or .css within the address Source/
answered by 09.02.2016 / 03:55