xam developer
xam developer

Reputation: 1983

Concatenating files with Gulp

Im new to using Gulp. I'm trying to concatenate my JavaScript files into a single file. Currently, I have the following:

gulpfile.js

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

var input = {
    js: './src/**/*.js'
};

var output = {
    js: './dist/myJavaScript.min.js'
}

gulp.task('default', ['clean', 'bundle-js']);

gulp.task('clean', function(callback) {

});

gulp.task('bundle-js', function() {
    gulp.src(input.js)
        .pipe(concat(output.js))
        .pipe(uglify())
    ;
});

When I run this, myJavaScript.min.js never gets generated. I ran gulp --verbose and I do not see any files being input. However, my directory structure looks like this:

/
  /src
    /childDirectory
      file2.js
    file1.js
  gulpfile.js
  package.json

Based on my understanding, the expression I used for input.js should get file1.js and file2.js. What am I doing wrong?

Upvotes: 1

Views: 265

Answers (2)

Gopinath Shiva
Gopinath Shiva

Reputation: 3892

You should give

  1. file name inside concat function, you should not give it as a path name

  2. add return before including source.

  3. add destination

try the following code,

gulp.task('bundle-js', function() {
    return gulp.src(input.js)
        .pipe(concat('myJavaScript.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('./dist/'));     
});

Upvotes: 1

SoEzPz
SoEzPz

Reputation: 15912

You are missing your destination folder.

gulp-concat-link

.pipe(gulp.dest('folderPathHere'));

Upvotes: 0

Related Questions