Check Older version if installed
Compile Sass to CSS with the help of gulp-sass PKG
Add following line on gulofile.js
Live Reloading => Auto sync
Run Following command:
To do this update following codes
$ npm rm --global gulp
Install Gulp Globally
$ npm install --global gulp-cliInitializing Project directory
npm initInstalling Dependencies
npm install --save-dev gulpCreatng 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.jsvar sass = require('gulp-sass');
Now add following line in gulpfile.jsgulp.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 terminalgulp watchNow you can see shuvrow.css file changes automatically.
Live Reloading => Auto sync
Run Following command:
npm install browser-sync --save-devAdd following line on gulpfile.js
var browserSync = require('browser-sync').create();
Now add following linesgulp.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-reloadingTo 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.

0 comments:
Post a Comment