Tuesday 14 March 2017

gulpfile.js - gulp task not showing error during compilation but not showing any result

I am learning coffeescript as a beginner so my tutorial took me through gulp.js in the first segment of the course. I followed the tutorial in creating a package.json file, then i installed some plugins and my package.json file looks like this below;

{
  "name": "MyFirstApp",
  "version": "0.1.0",
  "description": "First CoffeeScript Application",
  "author": "Ben Cipher-x",
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-coffee": "^2.3.3",
    "gulp-concat": "^2.6.1",
    "gulp-livereload": "^3.8.1",
    "gulp-ruby-sass": "^2.1.1",
    "gulp-uglify": "^2.0.1",
    "gulp-util": "^3.0.8",
    "tiny-lr": "^1.0.3"
  }
}

Afterwards, i ran this gulpfile.js code below;

var gulp    =       require('gulp'),
    gUtil   =       require('gulp-util'),
    uglify  =       require('gulp-uglify'),
    concat  =       require('gulp-concat'),
    livereload =    require('gulp-livereload'),
    lr =            require('tiny-lr'),
    server =        lr();

var jsSources = [
                  'components/scripts/scriptOne.js',
                  'components/scripts/scriptTwo.js'
                 ];


gulp.task('js', function(){
    return gulp.src(jsSources)
    .pipe(uglify())
    .pipe(concat('script.js'))
    .pipe(gulp.dest('js'));
});

gulp.task('watch', function(){
    gulp.watch(jsSources, ['js'])
})

gulp.task('default', ['js', 'watch']);

Now this is the output I get on the node.js command prompt but nothing is working

C:\Users\Ben\Desktop\coffeescript>gulp
[02:07:06] Using gulpfile ~\Desktop\coffeescript\gulpfile.js
[02:07:06] Starting 'js'...
[02:07:06] Starting 'watch'...
[02:07:06] Finished 'watch' after 9.06 ms
[02:07:06] Finished 'js' after 38 ms
[02:07:06] Starting 'default'...
[02:07:06] Finished 'default' after 12 μs
_

From my understanding of the code above, the node engine should first run the default task which will run the js and the watch task, the watch task is then expected to watch my two files (scriptOne and scriptTwo) which the js must have compressed and saved to a new file called script.js in the js folder.

But nothing like that is happening, I have been searching online for days but I've got no solution, I pray that someone can help me solve this problem by coming down to my evel of understanding and aiding my development in the course.

Thanks in hope, Ben



via Olanrewaju Femi

No comments:

Post a Comment