Skip to content

Commit

Permalink
npm run dev 后自动打开页面
Browse files Browse the repository at this point in the history
  • Loading branch information
蓝狐 committed Jul 6, 2017
1 parent 9aa5ab2 commit 7d9597a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

3、新建页面,需重新`npm run dev`才可以正常访问新建的页面。

4、`npm run dev`将会自动在浏览器打开页面,如未正常打开,请访问完整的路径`http:// localhost:8091/views/home/list.html`


## 前言
`vue2.0`上线已经有一段时间了,现在`vue2.1`也都已经发布了,是时候来更新基于vue的多页面脚手架了。
Expand Down
13 changes: 8 additions & 5 deletions build/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,24 @@ app.use(hotMiddleware)
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
app.use(staticPath, express.static('./static'))

var uri = 'http://localhost:' + port

var uri = 'http://localhost:' + port+'/views/home/list.html'

devMiddleware.waitUntilValid(function () {
console.log('> 构建完成,已自动在浏览器打开页面,如未自动打开,请手工复制下面的链接,复制到浏览器里打开。')
console.log('> Listening at ' + uri + '\n')
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
opn(uri)
}
})

module.exports = app.listen(port, function (err) {
if (err) {
console.log(err)
return
}

console.log("\n正在构建初始化中,构建完成后,将自动在浏览器打开页面。");
// when env is testing, don't need open it

if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
opn(uri)
}

})
2 changes: 1 addition & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
dev: {
env: require('./dev.env'),
port: 8091,
autoOpenBrowser: false,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>vux2</title>
<script>window.location.href='/views/home/list.html';</script>
</head>
<body>
<div id="app-box"></div>
Expand Down

0 comments on commit 7d9597a

Please sign in to comment.