Add Gulp Plugins

Install Gulp SASS Plugin
- In command prompt, type 'npm install gulp-sass --save-dev'

Install Gulp Browser Sync Plugin
- In command prompt, type 'npm install -g browser-sync' or 'npm install browser-sync gulp --save-dev'

Add JS code of these plugin in 'gulpfile.js' which you have created manually.
var gulp        = require('gulp');
var browserSync = require('browser-sync').create();
var sass        = require('gulp-sass');

// Static Server + watching scss/html files
gulp.task('serve', ['sass'], function() {

    browserSync.init({
        server: "./app"
    });

    gulp.watch("app/scss/*.scss", ['sass']);
    gulp.watch("app/js/*.js").on('change', browserSync.reload);
    gulp.watch("app/*.html").on('change', browserSync.reload);
});

// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function() {
    return gulp.src("app/scss/*.scss")
        .pipe(sass().on('error', function(err) {
            console.error(err.message);
            browserSync.notify(err.message, 3000); // Display error in the browser
            this.emit('end'); // Prevent gulp from catching the error and exiting the watch process
        }))
        .pipe(gulp.dest("app/css"))
        .pipe(browserSync.stream());
});

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

For more plugins, go to: http://gulpjs.com/plugins/

Share this

Related Posts