使gulp.js打开非默认浏览器 [英] Make gulp.js open non-default browser
问题描述
标题几乎说明了一切.我在Windows 10上,并且有一个以npm start
开头的节点应用程序. (我对node.js几乎一无所知.)该应用程序在gulp.js上运行.即使Chrome是我的默认浏览器,我仍需要在Firefox中打开该应用.我怎样才能做到这一点?这是现在打开应用程序的代码;文档并不暗示open
参数有这样的选择:
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
}));
});
gulp.task('webserver', function() {
gulp.src('./app')
.pipe(webserver({
livereload: true,
open: true,
defaultFile: 'index.html',
port: serverPort
}));
});
推荐答案
通过在控制台中键入以下内容来安装gulp-open
Install gulp-open by typing the following in to your console
npm install gulp-open --save
在gulpfile.js的顶部添加以下内容
Add the following to the top of your gulpfile.js
var open = require('gulp-open');
在gulpfile.js的末尾添加以下内容
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));
});
在您的gulp默认值中添加浏览器".这实际上是在
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']);
在控制台中输入gulp
这篇关于使gulp.js打开非默认浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!