Skip to content

Commit

Permalink
Add --open option to automatically launch in default browser (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon93s authored and devongovett committed Dec 11, 2017
1 parent 35c65a3 commit f8b3d55
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ program
.command('serve [input]')
.description('starts a development server')
.option('-p, --port <port>', 'set the port to serve on. defaults to 1234')
.option('-o, --open', 'automatically open in default browser')
.option(
'-d, --out-dir <path>',
'set the output directory. defaults to "dist"'
Expand Down Expand Up @@ -93,7 +94,10 @@ function bundle(main, command) {
const bundler = new Bundler(main, command);

if (command.name() === 'serve') {
bundler.serve(command.port || 1234);
const server = bundler.serve(command.port || 1234);
if (command.open) {
require('opn')(`http://localhost:${server.address().port}`);
}
} else {
bundler.bundle();
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"micromatch": "^3.0.4",
"mkdirp": "^0.5.1",
"node-libs-browser": "^2.0.0",
"opn": "^5.1.0",
"parse-json": "^4.0.0",
"physical-cpu-count": "^2.0.0",
"postcss": "^6.0.10",
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2508,6 +2508,10 @@ is-windows@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.1.tgz#310db70f742d259a16a369202b51af84233310d9"

is-wsl@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d"

isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
Expand Down Expand Up @@ -3413,6 +3417,12 @@ onetime@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/onetime/-/onetime-1.1.0.tgz#a1f7838f8314c516f05ecefcbc4ccfe04b4ed789"

opn@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/opn/-/opn-5.1.0.tgz#72ce2306a17dbea58ff1041853352b4a8fc77519"
dependencies:
is-wsl "^1.1.0"

optimist@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
Expand Down

0 comments on commit f8b3d55

Please sign in to comment.