Giwrgos Gkogkas
Giwrgos Gkogkas

Reputation: 479

Gulp Concat no output file

I am trying to concatinate my js files with gulp's concate module.

My projects path to js files is: project/public/js/vendor/.

In vendor are all the plugins I use and I want to concatinate them to a single file

I use the following code to execute my task.

var gulp = require('gulp'),
concat = require('gulp-concat');

gulp.task('scripts',function(){
    return gulp.src('./vendor/*.js')
        .pipe(concat('global.js'))
        .pipe(gulp.dest('concat/'));

});

gulp.task('default', ['scripts']);

I want to export the file to concat folder which is located into /js, but I get no file. The code executes with no error report.

[gulp] Using gulpfile /var/www/vhosts/site.dev/httpdocs/project/gulpfile.js
[gulp] Starting 'scripts'...
[gulp] Finished 'scripts' after 9.2 ms
[gulp] Starting 'default'...
[gulp] Finished 'default' after 8.8 μs

Did I do something wrong?

Edit 1

I tried to log the count as it was suggested and returned:

[gulp] Using gulpfile /var/www/vhosts/site.dev/httpdocs/laravel/gulpfile.js
[gulp] Starting 'scripts'...
[gulp] Finished 'scripts' after 12 ms
[gulp] Starting 'default'...
[gulp] Finished 'default' after 9.37 μs

Does this means that it didn't select any js?

Upvotes: 8

Views: 4254

Answers (4)

Manuel Manhart
Manuel Manhart

Reputation: 5455

I tried all the answers and in my case it was simply the fact that I had hooked it too soon into the gulp lifecycle and therefor build / my file was overwritten afterwards.

So if everything from the other answers is okay have a look into your lifecycle hooks.

Upvotes: 0

mnishiguchi
mnishiguchi

Reputation: 2241

I had the same issue now and in my case, the cause was simply a syntactic error in one of the files.

Upvotes: 0

Santiago Benitez
Santiago Benitez

Reputation: 362

it might be related with the place where you are running your gulpfile. You're saying the path for your files are at:

 project/public/js/vendor

but your gulpfile is running at

project/gulpfile

so gulp is not finding any file at:

./vendor/*.js

and that's because the path might be getting resolved to:

project/vendor/*.js

What you should do is:

  1. Try using as path for the files ./public/vendor/*.js
  2. If it doesn't work, you need to know where your working directory is, to know this log where you're:

     cosole.log(__dirname)
    
  3. Then you can either use that working directory for your path or you can path the working directory as input to the task and then do something like:

     const path = require('path);
    
     ...
    
     let jspath = path.join(basePathInput, 'public/vendor/*.js')
     return gulp.src(jspath).
            ....
    

Upvotes: 0

harishr
harishr

Reputation: 18055

mostly there are not source files being selected, use gulp-count to print the number of files selected

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

gulp.task('scripts',function(){
    return gulp.src('./vendor/*.js')
        .pipe(count('## js-files selected'))
        .pipe(concat('global.js'))
        .pipe(gulp.dest('concat/'));

});

if you get count as 0, given your path is project/public/js/vendor/ change your gulp.src to gulp.src('project/public/js/vendor/**/*.js')

Upvotes: 5

Related Questions