1

I am trying to concatinate multiple files using gulp and gulp-concat modules of npm.

The following is the code snippet I have used.

gulp.src(['../a.js', '../b.js', '../c.js'])
    .pipe(concat('destination.js'))
    .pipe(gulp.dest('destination/path/'))
    .on('error', () => {
        console.error('Error');
     })
    .on('finish', () => {
        console.log('Success');
    });

The error event listener is not getting triggered when the file for suppose b.js or anyother is not found in the specified path.

The event finish is getting triggered anyway.

How do find error such as file not found in this process?

Thanks for the help in advance

Krishna E
  • 29
  • 6
  • Does this answer your question? [How to make Gulp.src fail if a file is missing?](https://stackoverflow.com/questions/33209074/how-to-make-gulp-src-fail-if-a-file-is-missing) – jonrsharpe Oct 12 '20 at 08:53

2 Answers2

0

I finally found a solution for this from the below post

How to make Gulp.src fail if a file is missing?

I Used the files-exist npm package to check if all files exist or not.

Krishna E
  • 29
  • 6
0

You can use gulp-plumber to get error while build.

Example:

Step 1: Install gulp-plumber:

npm i gulp-plumber --save-dev

Step 2: Require the gulp plmber module in gulpfile:

var plumber = require('gulp-plumber');   

Step 3: Usage

gulp.src(['../a.js', '../b.js', '../c.js'])
.pipe(plumber())
.pipe(concat('destination.js'))
.pipe(plumber.stop())
.pipe(gulp.dest('dist/js'));
Anushil Kumar
  • 674
  • 8
  • 8