0

I am a new to gulp and I am working in Gulpfile.js where I have this so far

var gulp = require('gulp');
var sass = require('gulp-sass');
var plumber = require('gulp-plumber');

gulp.task('sass', function() {
  gulp.src('public/stylesheets/style.scss')
    .pipe(plumber())
    .pipe(sass())
    .pipe(gulp.dest('public/stylesheets'));
});

gulp.task('watch', function() {
  gulp.watch('public/stylesheets/*.scss', ['sass']);
});

gulp.task('default', ['sass', 'watch']);

when I run $ gulp nothing happens, and I want a gulp file which responds to the gulp command and opens the page in the browser.

There is the I have my folders:

enter image description here

Which is the proper task to accomplish what I want?

Reacting
  • 5,543
  • 7
  • 35
  • 86

1 Answers1

1
'use strict';

var gulp = require('gulp');
var open = require('gulp-open');


// Default usage: 
// Open one file with default application 

gulp.task('open', function(){
  gulp.src('./index.html')
  .pipe(open());
});
Josh
  • 1,455
  • 19
  • 33
  • so I need to install those modules? `os` and `gulp-open`? – Reacting May 07 '16 at 16:38
  • Well you also need to configure the options. Choose what kind of task you would like: npmjs.com/package/gulp-open – Josh May 07 '16 at 16:43
  • I did it now, but it is opening only a file `file:///Users/Marcelo/Documents/Projects/showstracker/public/index.html` I need it to open something like localhost:3000 in the browser – Reacting May 07 '16 at 16:44
  • you have to use an absolute path. ```var options = { uri: 'localhost:3000', app: '/Applications/Google\ Chrome.app' }; gulp.src('./') .pipe(open(options));``` – Josh May 07 '16 at 16:45
  • How to open my index.html page after I run npm start? – Rohit Singh Jan 26 '21 at 23:19
  • @RohitSingh You would need to do so with node using `readFile` See this for example https://stackoverflow.com/questions/4720343/loading-basic-html-in-node-js – Josh Feb 09 '21 at 16:21