8

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?

4
  • some clearifications please: "concat folder which is located into /js" - can you please explain the folder structure? both for the src and the dest Did you check if the files global.js is present in ./vendor/ ? Commented Aug 20, 2015 at 12:19
  • From the current info... can it be that you just need to use gulp.dest('./concat/')? Commented Aug 20, 2015 at 12:21
  • Thatkookooguy: I checked vendor I didn't find the required file, also concat folrder is in general js folder named "js" and is empy, vendor is inside the same folder and containes some .js files. Commented Aug 20, 2015 at 12:28
  • 1
    did you try what I suggested in my second comment? Also, it's better to edit your question and include the new data than write it in a comment. Commented Aug 20, 2015 at 12:36

4 Answers 4

5

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')

Sign up to request clarification or add additional context in comments.

Comments

0

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). .... 

Comments

0

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

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.