Thursday, September 1, 2016

Up & Running With Gulp

Check Older version if installed

$ npm rm --global gulp
  Install Gulp Globally
$ npm install --global gulp-cli
Initializing Project directory
npm init
Installing Dependencies
npm install --save-dev gulp
Creatng gulpfile.js in root directory
var gulp = require('gulp');

gulp.task('default', function() {
  // place code for your default task here
});
Preprocessing with Gulp 

Compile Sass to CSS with the help of gulp-sass PKG

$ npm install gulp-sass --save-dev

 --save-dev flag to ensure that gulp-sass gets added to devDependencies in package.json Now add following line to gulpfile.js
var sass = require('gulp-sass');
  Now add following line in gulpfile.js
gulp.task('sass', function(){
    return gulp.src('css/sass/shuvrow.scss')
        .pipe(sass()) // Using gulp-sass
        .pipe(gulp.dest('css'))
});
Now add watch to change dynamically.
 Add following line on gulofile.js
gulp.task('watch', function(){
    gulp.watch('css/sass/shuvrow.scss', ['sass']);
    // Other watchers
})
Now run following command in terminal
gulp watch
Now you can see shuvrow.css file changes automatically.
Live Reloading => Auto sync 
Run Following command:

npm install browser-sync --save-dev
Add following line on gulpfile.js
var browserSync = require('browser-sync').create();
Now add following lines
gulp.task('browserSync', function() {
  browserSync.init({
    server: {
      baseDir: ''
    },
  })
})
Now update following code
gulp.task('sass', function(){
    return gulp.src('css/sass/main.scss')
        .pipe(sass()) // Using gulp-sass
        .pipe(gulp.dest('css'))
});
to
gulp.task('sass', function(){
    return gulp.src('css/sass/main.scss')
        .pipe(sass()) // Using gulp-sass
        .pipe(gulp.dest('css'))
        .pipe(browserSync.reload({
            stream: true
        }))
});
Now, we have to run both the watch and browserSync tasks at the same time for live-reloading
To do this update following codes
gulp.task('watch',function(){
    gulp.watch('css/sass/main.scss', ['sass']);
    // Other watchers
});
to
gulp.task('watch',['browserSync','sass'], function(){
    gulp.watch('css/sass/main.scss', ['sass']);
    // Other watchers
});
Now run gulp watch command on terminal to see all new changes on browser automatically.

Related Posts:

  • Create Your own command on Laravel 5.2 In Laravel application , when you try this command php artisan you would see lots of command for laravel application. So if you want to create your own command, laravel provide you very easy way to do this. Here is the … Read More
  • Laravel 5.2 queuing Event listeners First , we need to create Event and to listen event, we also have to create listener. To do this , laravel provides us several ways. The easiest way to create event and corresponding listener we can use this command php ar… Read More
  • Laravel 5.2 Implicit model binding In Laravel 5.2 new feature called implicit model binding added. Which can be implement efficiently and in a very easy manner. Here how its done : In your routes.php file create a new route Route::get('user',function(){}); … Read More
  • Laravel 5.2 using queue to send email To sent email after desired number of second, first change the .env file as follow. First provide database credential set QUEUE_DRIVER=sync to QUEUE_DRIVER=database Normally , QUEUE_DRIVER=sync tries to sent email immedi… Read More
  • Install LAMP and PHPmyAdmin && PHPpgAdmin on Ubuntu 14.04 Install LAMP Steps are: sudo apt-get update sudo apt-get install apache2 sudo apt-get install mysql-server php5-mysql sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt sudo gedit /etc/apache2/conf-available/serve-… Read More

0 comments:

Post a Comment