Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gulp js src - copy and usage of base

I have gulp task to copy js files

This doesn't work

gulp.src('./**/*.js', {base: '../src/main/'})
    .pipe(gulp.dest('../target/dist'));

This works:

gulp.src('../src/main/**/*.js', {base: '../src/main/'})
        .pipe(gulp.dest('../target/dist'));

So whats the use of base here ? if i have to put whole path in first param, why should i use base ?

is there any official documentation about gulp src ? is it worth using gulp over grunt with limited documentation ?

[UPDATE BASED ON COMMENT]
Why am i using base ?

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

and moreoever gulp.src can take array of paths so i would need base.

like image 814
Venkat Reddy Avatar asked Mar 27 '14 00:03

Venkat Reddy


People also ask

What is Gulp SRC?

src() # The gulp. src() function takes a glob (i.e. a string matching one or more files) or an array of globs and returns a stream that can be piped to plugins. Gulp uses node-glob to get the files from the glob or globs you specify.

What is Gulpfile JS used for?

Gulp is a task runner that uses Node. js as a platform. Gulp purely uses the JavaScript code and helps to run front-end tasks and large-scale web applications. It builds system automated tasks like CSS and HTML minification, concatenating library files, and compiling the SASS files.

What is Gulp Gulpfile?

Gulpfile explained A gulpfile is a file in your project directory titled gulpfile. js (or capitalized as Gulpfile. js , like Makefile), that automatically loads when you run the gulp command.

What is a gulp pipe?

Gulp plugins are Node Transform Streams that encapsulate common behavior to transform files in a pipeline - often placed between src() and dest() using the . pipe() method. They can change the filename, metadata, or contents of every file that passes through the stream.


1 Answers

The use of .src() is documented on the vinyl-fs github repo: https://github.com/wearefractal/vinyl-fs

The base property is used to determine the file names when saving in .dest().

I think you need to set the current working directory:

gulp
  .src('./**/*.js', {cwd: '../src/main/'})
  .pipe(gulp.dest('../target/dist'))
;
like image 162
tim-montague Avatar answered Oct 16 '22 06:10

tim-montague