D
D
Dmitry Khristoev2015-08-30 18:09:36
Sass
Dmitry Khristoev, 2015-08-30 18:09:36

Gulp newbie: server and reload - how to do it right?

Hello! I'm learning gulp, there was a server and livereload question, so there are several questions:
- gulp-connect or gulp-webserver - the lessons from loftblog use connect, but the lessons from September 2014, read somewhere recently that it's more relevant to use webserver now. What is right?
- in the lessons from DevTips they use browser-sync but I really can’t install it, I installed Python + Visual Studio Community 2015, but when installing npm install --save-dev browser-sync it gives an error (in attack)
96ad148c85144b458122920c88ab7b86.png
What’s right, gulp-connect - gulp-webserver or still try to fight browser-sync ? Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2015-08-30
@Haoss

installed Python + Visual Studio Community 2015, but when installing npm install --save-dev browser-sync gives an error

Weird. I have never installed python or studio. Browser-sync is normally set.

D
Dmitry Khristoev, 2015-09-04
@Haoss

I did everything, it seems to work, but, for example, I get an error when saving the file (attached) that file to import not found or unreadeble, I have to press ctrl + s several times, gulpgile.js in the attack, maybe I have something configured incorrectly?
0cfe6cc1acc140978497b989cd824458.png

"use script"

var gulp = require('gulp'),
  browserSync = require('browser-sync'),
  sass = require('gulp-sass'),
  uncss = require('gulp-uncss'),
  autoprefixer = require('gulp-autoprefixer'),
  sourcemaps = require('gulp-sourcemaps'),
  rename = require("gulp-rename"),
  minifyCss  = require('gulp-minify-css'),
  plumber = require('gulp-plumber'),
  jade = require('gulp-jade'),
  browserSync = require('browser-sync');

var plugins = require("gulp-load-plugins")();

// Static server
gulp.task('browser-sync', ['sass', 'html', 'js'], function() {
    browserSync.init({
      server: {
          baseDir: "./"
      },
      notify: false
    });
});

// jade
gulp.task('jade', function() {
  gulp.src('assets/template/*.jade')
    .pipe(plumber())
    .pipe(jade({
      pretty: true
    }))
    .pipe(gulp.dest('./'));
})

gulp.task('sass', function() {
  gulp.src('assets/css/main.sass')
    .pipe(plumber())
    .pipe(plugins.sourcemaps.init())
    .pipe(sass())
    .pipe(autoprefixer({
      browsers: ['last 2 versions'],
      cascade: false
    }))
    // .pipe(uncss({
    //    html: ['*.html']
    // }))
    .pipe(plugins.sourcemaps.write("./"))
    // .pipe(minifyCss({compatibility: 'ie8'}))
    // .pipe(rename("main.min.css"))    
    .pipe(gulp.dest('assets/css/'))
    .pipe(browserSync.reload({stream:true}));
});

gulp.task('html', function(){
  gulp.src('./*.html')
    .pipe(browserSync.reload({stream:true}))
});

gulp.task('js', function(){
  gulp.src('assets/**/*.js')
    .pipe(browserSync.reload({stream:true}))
});

gulp.task('watch', function () {
  gulp.watch('assets/css/**/*.sass', ['sass']);
  gulp.watch('./*.html', ['html']);
  gulp.watch('assets/template/**/*.jade', ['jade']);
  gulp.watch('assets/**/*.js', ['js']);
});

gulp.task('default', ['browser-sync', 'watch']);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question