John Alexander
John Alexander

Reputation: 871

Make gulp.js open non-default browser

The title pretty much says it all. I'm on Windows 10, and I have a node app that I start with npm start. (I know almost nothing about node.js.) The app runs on gulp.js. I need the app to open in Firefox, even though Chrome is my default browser. How can I do this? Here's the code that opens the app now; the docs don't allude to there being such an option for the open parameter:

gulp.task('webserver', function() { gulp.src('./app') .pipe(webserver({ livereload: true, open: true, defaultFile: 'index.html', port: serverPort })); });

Upvotes: 3

Views: 2917

Answers (1)

Aaron
Aaron

Reputation: 3255

Install gulp-open by typing the following in to your console

npm install gulp-open --save

Add the following to the top of your gulpfile.js

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

Add the following to the end of your gulpfile.js

gulp.task('browser', function(){
  var options = {
    uri: 'localhost:<enter the port you are using here>',
    app: 'firefox'
  };
  gulp.src(__filename)
  .pipe(open(options));
});

Add 'browser' to your gulp default. This is what actually opens the browser at the port you are running your app on

gulp.task('default', ['webserver', 'browser']);

in console type gulp

Upvotes: 1

Related Questions