1

I am trying to create all.js file from all .js files in one folder with the help of gulp. But i am not getting all.js file.

Steps i have followed as follows:

  1. Created Gulp.js file as below

File: gulpfile.js

// grab our gulp packages
var gulp  = require('gulp'),
    gutil = require('gulp-util'),
    concat = require('gulp-concat-util');

// create a default task and just log a message
gulp.task('default', function() {
  return gutil.log('Gulp is running!')
});

gulp.task('scripts', function() {
  gulp.src(['./js/*.js'])
    .pipe(concat.scripts('all.js'))
    .pipe(uglify())
    .pipe(gulp.dest('./dist/'))
});
  1. run gulp command.

After running gulp, i am getting message as Gulp is running as mentioned in file. But Js file is not created.

Any help shall be appreciated.

Gags
  • 3,759
  • 8
  • 49
  • 96

1 Answers1

1

You're not running the task. You need to run the command gulp scripts

Gulp is a task runner. It allows you to specify tasks. The default task is run when you run the gulp command. If you want to run a task other than the default task you must

  1. Run gulp {{taskname}} where {{taskname}} is callback called via gulp.task in your gulpfile or
  2. Call the specified task via the default task.

You haven't done either. So when you run gulp from the command line, all you are running is the default task, which does nothing except call gutil.log and then return.

Adam Jenkins
  • 51,445
  • 11
  • 72
  • 100
  • with `gulp scripts` i get the error `[21:53:21] TypeError: concat.scripts is not a function` – Gags Feb 11 '17 at 16:28
  • `concat.scripts` was added in v0.5.5 (https://github.com/mgcrea/gulp-concat-util/commit/759d721bd581b05bab27af9dc4087a730d5d052a). Assuming you have installed the latest version with `npm install gulp-concat-util`, it should work fine. Not sure why it doesn't work, but it should still work even without the `.scripts`. Change it to `concat('all.js')` and see if that works. You can always `console.log(concat)` inside your `scripts` task to see what's available. – Adam Jenkins Feb 11 '17 at 16:36
  • sorry,.. i am new to gulp but this time it is `[22:12:30] ReferenceError: uglify is not defined` – Gags Feb 11 '17 at 16:43
  • You haven't required `uglify` at the top of your `gulpfile` where you have required everything else. Before you `var uglify = require('gulp-uglify');`, make sure you have installed it via `npm install gulp-uglify --save-dev` (Sorry, an earlier version of this comment said just to install `uglifyjs`, you need `gulp-uglify`) – Adam Jenkins Feb 11 '17 at 16:45
  • New Error: `Error: Cannot find module 'uglify'` .. I hav installed via npm as well – Gags Feb 11 '17 at 16:47
  • @Gags Check my edited comment. You're supposed to install `gulp-uglify` not `uglifyjs`. Sorry about the confusion. – Adam Jenkins Feb 11 '17 at 16:49
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/135455/discussion-between-gags-and-adam). – Gags Feb 11 '17 at 16:50