Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MuGuiLin
uni-app
提交
606c95de
U
uni-app
项目概览
MuGuiLin
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
606c95de
编写于
9月 30, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(h5): Compatible with vite 2.6.1
上级
ab4bd0c5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
102 addition
and
0 deletion
+102
-0
packages/vite-plugin-uni/src/cli/logger.ts
packages/vite-plugin-uni/src/cli/logger.ts
+89
-0
packages/vite-plugin-uni/src/cli/server.ts
packages/vite-plugin-uni/src/cli/server.ts
+13
-0
未找到文件。
packages/vite-plugin-uni/src/cli/logger.ts
0 → 100644
浏览文件 @
606c95de
import
os
from
'
os
'
import
{
AddressInfo
,
Server
}
from
'
net
'
import
chalk
from
'
chalk
'
import
{
Logger
,
ResolvedConfig
,
ServerOptions
}
from
'
vite
'
export
function
printHttpServerUrls
(
server
:
Server
,
config
:
ResolvedConfig
,
_options
:
ServerOptions
):
void
{
const
address
=
server
.
address
()
const
isAddressInfo
=
(
x
:
any
):
x
is
AddressInfo
=>
x
.
address
if
(
isAddressInfo
(
address
))
{
const
hostname
=
resolveHostname
(
true
/*options.host*/
)
const
protocol
=
config
.
server
.
https
?
'
https
'
:
'
http
'
printServerUrls
(
hostname
,
protocol
,
address
.
port
,
config
.
base
,
config
.
logger
.
info
)
}
}
function
printServerUrls
(
hostname
:
Hostname
,
protocol
:
string
,
port
:
number
,
base
:
string
,
info
:
Logger
[
'
info
'
]
):
void
{
if
(
hostname
.
host
===
'
127.0.0.1
'
)
{
const
url
=
`
${
protocol
}
://
${
hostname
.
name
}
:
${
chalk
.
bold
(
port
)}${
base
}
`
info
(
` > Local:
${
chalk
.
cyan
(
url
)}
`
)
if
(
hostname
.
name
!==
'
127.0.0.1
'
)
{
info
(
` > Network:
${
chalk
.
dim
(
'
use `--host` to expose
'
)}
`
)
}
}
else
{
Object
.
values
(
os
.
networkInterfaces
())
.
flatMap
((
nInterface
)
=>
nInterface
??
[])
.
filter
((
detail
)
=>
detail
&&
detail
.
address
&&
detail
.
family
===
'
IPv4
'
)
.
map
((
detail
)
=>
{
const
type
=
detail
.
address
.
includes
(
'
127.0.0.1
'
)
?
'
Local:
'
:
'
Network:
'
const
host
=
detail
.
address
.
replace
(
'
127.0.0.1
'
,
hostname
.
name
)
const
url
=
`
${
protocol
}
://
${
host
}
:
${
chalk
.
bold
(
port
)}${
base
}
`
return
` >
${
type
}
${
chalk
.
cyan
(
url
)}
`
})
.
forEach
((
msg
)
=>
info
(
msg
))
}
}
export
interface
Hostname
{
// undefined sets the default behaviour of server.listen
host
:
string
|
undefined
// resolve to localhost when possible
name
:
string
}
export
function
resolveHostname
(
optionsHost
:
string
|
boolean
|
undefined
):
Hostname
{
let
host
:
string
|
undefined
if
(
optionsHost
===
undefined
||
optionsHost
===
false
||
optionsHost
===
'
localhost
'
)
{
// Use a secure default
host
=
'
127.0.0.1
'
}
else
if
(
optionsHost
===
true
)
{
// If passed --host in the CLI without arguments
host
=
undefined
// undefined typically means 0.0.0.0 or :: (listen on all IPs)
}
else
{
host
=
optionsHost
}
// Set host name to localhost when possible, unless the user explicitly asked for '127.0.0.1'
const
name
=
(
optionsHost
!==
'
127.0.0.1
'
&&
host
===
'
127.0.0.1
'
)
||
host
===
'
0.0.0.0
'
||
host
===
'
::
'
||
host
===
undefined
?
'
localhost
'
:
host
return
{
host
,
name
}
}
packages/vite-plugin-uni/src/cli/server.ts
浏览文件 @
606c95de
...
...
@@ -12,6 +12,7 @@ import { hasOwn } from '@vue/shared'
import
{
parseManifestJson
}
from
'
@dcloudio/uni-cli-shared
'
import
{
CliOptions
}
from
'
.
'
import
{
addConfigFile
,
cleanOptions
}
from
'
./utils
'
import
{
printHttpServerUrls
}
from
'
./logger
'
export
async
function
createServer
(
options
:
CliOptions
&
ServerOptions
)
{
const
server
=
await
createViteServer
(
...
...
@@ -23,6 +24,18 @@ export async function createServer(options: CliOptions & ServerOptions) {
})
)
await
server
.
listen
()
const
info
=
server
.
config
.
logger
.
info
info
(
chalk
.
cyan
(
`\n vite v
${
require
(
'
vite/package.json
'
).
version
}
`
)
+
chalk
.
green
(
` dev server running at:\n`
),
{
clear
:
!
server
.
config
.
logger
.
hasWarned
,
}
)
printHttpServerUrls
(
server
.
httpServer
!
,
server
.
config
,
options
)
}
export
async
function
createSSRServer
(
options
:
CliOptions
&
ServerOptions
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录