Make gulp.js open non-default browser

笑着哭i 提交于 2019-12-10 23:15:21

问题


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 })); });


回答1:


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



来源:https://stackoverflow.com/questions/37597372/make-gulp-js-open-non-default-browser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!