bier hier
bier hier

Reputation: 22540

How to open the chrome browser with gulp-open?

I am using gulp-open with gulp in windows 7:

gulp.task('op', function(){
    var options = {
        uri: 'localhost:8080',
        app: 'chrome'
    };
    gulp.src(__filename)
        .pipe(open(options));
});

The index.html file opens with the app when I use app:'Firefox' but when I use the chrome option it opens an empty index.html? How can I fix this?

Upvotes: 4

Views: 6617

Answers (3)

Chidi-Nwaneto
Chidi-Nwaneto

Reputation: 654

This is a snippet of my code that solves the issue for me, you can use it to modify yours accordingly:

var gulp = require('gulp');
var liveServer = require('gulp-live-server');
var browserSync = require('browser-sync');

gulp.task('live-server', function(done){
    var server = new liveServer('server/main.js');
    server.start();
    done();
})

gulp.task('serve', gulp.series('live-server', function(done){
    browserSync.init(null,{
        proxy:"http://localhost:7777",
        port:9001,
        open: true
    })
    done();
}));

Upvotes: 1

Matthew Ellison
Matthew Ellison

Reputation: 176

I only added http:// to the uri and it worked for me.

gulp.task('op', function(){
    var options = {
        uri: 'http://localhost:8080',
        app: 'chrome'
    };
    gulp.src(__filename)
    .pipe(open(options));
});

Upvotes: 1

joeyfb
joeyfb

Reputation: 3239

Depending on the OS you need to refer to the chrome app differently in options:

'google-chrome' // Linux 

'chrome' // Windows 

'google chrome' or 'Google Chrome' // OSX 

Refer to section Options.app in the NPM documentation about gulp-open.

Upvotes: 10

Related Questions