K
K
kpanyushin2017-04-18 22:23:00
gulp.js
kpanyushin, 2017-04-18 22:23:00

How to immediately open the index.html file when running the gulp command?

Actually, there is a gulpfile.js file, the code is below:

var gulp = require('gulp');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;

var src = {
html:['index.html'],
};

//tasks
gulp.task('default', ['watch'], function(){
  gulp.start('watch');
});

gulp.task('browserSync', function() {
  browserSync.init({
    server: {
      baseDir: 'app',
      index: 'index.html'
    },
    port: 3000,
    open: true
  });
});

gulp.task('sass', function() {
  return gulp.src('app/scss/**/*.scss')
    .pipe(sass())
    .pipe(gulp.dest('app/css'))
    .pipe(browserSync.reload({
      stream: true
    }))
});

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

gulp.task('watch', ['browserSync', 'sass'], function(){
  	gulp.watch('./app/scss/**/*.scss', ['sass']); 
  	gulp.watch('.app/index.html', ['html']);
  
})

how to open index.html file immediately when running gulp command?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Filippov, 2017-04-18
@kpanyushin

in theory, browsersync should start immediately

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question