Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Velpro187
uni-app
提交
9d602447
U
uni-app
项目概览
Velpro187
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9d602447
编写于
7月 08, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(cli): Compatible with hbx
上级
1752b501
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
103 addition
and
55 deletion
+103
-55
packages/uni-app-vite/dist/plugin.js
packages/uni-app-vite/dist/plugin.js
+4
-5
packages/uni-app-vite/src/plugin.ts
packages/uni-app-vite/src/plugin.ts
+4
-5
packages/uni-cli-shared/src/hbx.ts
packages/uni-cli-shared/src/hbx.ts
+18
-4
packages/vite-plugin-uni/src/cli/build.ts
packages/vite-plugin-uni/src/cli/build.ts
+25
-19
packages/vite-plugin-uni/src/cli/server.ts
packages/vite-plugin-uni/src/cli/server.ts
+24
-20
packages/vite-plugin-uni/src/cli/utils.ts
packages/vite-plugin-uni/src/cli/utils.ts
+28
-2
未找到文件。
packages/uni-app-vite/dist/plugin.js
浏览文件 @
9d602447
...
...
@@ -17,15 +17,14 @@ exports.UniAppPlugin = {
config
()
{
return
{
build
:
{
lib
:
{
name
:
'
AppService
'
,
entry
:
uni_cli_shared_1
.
resolveMainPathOnce
(
process
.
env
.
UNI_INPUT_DIR
),
formats
:
[
'
iife
'
],
},
rollupOptions
:
{
input
:
uni_cli_shared_1
.
resolveMainPathOnce
(
process
.
env
.
UNI_INPUT_DIR
),
external
:
[
'
vue
'
],
output
:
{
name
:
'
AppService
'
,
format
:
'
iife
'
,
entryFileNames
:
'
app-service.js
'
,
manualChunks
:
undefined
,
globals
:
{
vue
:
'
Vue
'
,
},
...
...
packages/uni-app-vite/src/plugin.ts
浏览文件 @
9d602447
...
...
@@ -25,15 +25,14 @@ export const UniAppPlugin: UniVitePlugin = {
config
()
{
return
{
build
:
{
lib
:
{
name
:
'
AppService
'
,
entry
:
resolveMainPathOnce
(
process
.
env
.
UNI_INPUT_DIR
),
formats
:
[
'
iife
'
],
},
rollupOptions
:
{
input
:
resolveMainPathOnce
(
process
.
env
.
UNI_INPUT_DIR
),
external
:
[
'
vue
'
],
output
:
{
name
:
'
AppService
'
,
format
:
'
iife
'
,
entryFileNames
:
'
app-service.js
'
,
manualChunks
:
undefined
,
globals
:
{
vue
:
'
Vue
'
,
},
...
...
packages/uni-cli-shared/src/hbx.ts
浏览文件 @
9d602447
import
slash
from
'
slash
'
import
path
from
'
path
'
import
{
once
}
from
'
@dcloudio/uni-shared
'
process
.
env
.
UNI_HBUILDERX_PLUGINS
=
process
.
env
.
UNI_HBUILDERX_PLUGINS
||
path
.
resolve
(
__dirname
,
'
../../../../../
'
)
export
const
isInHBuilderX
=
once
(()
=>
{
const
{
UNI_HBUILDERX_PLUGINS
,
UNI_CLI_CONTEXT
}
=
process
.
env
if
(
!
UNI_HBUILDERX_PLUGINS
||
!
UNI_CLI_CONTEXT
)
{
const
{
UNI_HBUILDERX_PLUGINS
}
=
process
.
env
if
(
!
UNI_HBUILDERX_PLUGINS
)
{
return
false
}
return
slash
(
UNI_CLI_CONTEXT
).
startsWith
(
slash
(
UNI_HBUILDERX_PLUGINS
))
try
{
const
{
name
}
=
require
(
path
.
resolve
(
UNI_HBUILDERX_PLUGINS
,
'
about/package.json
'
))
return
name
===
'
about
'
}
catch
(
e
)
{
// console.error(e)
}
return
false
})
export
const
runByHBuilderX
=
once
(()
=>
{
...
...
packages/vite-plugin-uni/src/cli/build.ts
浏览文件 @
9d602447
...
...
@@ -2,15 +2,17 @@ import fs from 'fs-extra'
import
path
from
'
path
'
import
{
build
as
buildByVite
,
BuildOptions
}
from
'
vite
'
import
{
CliOptions
}
from
'
.
'
import
{
cleanOptions
}
from
'
./utils
'
import
{
addConfigFile
,
cleanOptions
}
from
'
./utils
'
export
async
function
build
(
options
:
CliOptions
)
{
await
buildByVite
({
root
:
process
.
env
.
VITE_ROOT_DIR
,
logLevel
:
options
.
logLevel
,
clearScreen
:
options
.
clearScreen
,
build
:
cleanOptions
(
options
)
as
BuildOptions
,
})
await
buildByVite
(
addConfigFile
({
root
:
process
.
env
.
VITE_ROOT_DIR
,
logLevel
:
options
.
logLevel
,
clearScreen
:
options
.
clearScreen
,
build
:
cleanOptions
(
options
)
as
BuildOptions
,
})
)
}
export
async
function
buildSSR
(
options
:
CliOptions
)
{
...
...
@@ -21,12 +23,14 @@ export async function buildSSR(options: CliOptions) {
ssrBuildClientOptions
.
ssrManifest
=
true
ssrBuildClientOptions
.
outDir
=
process
.
env
.
UNI_OUTPUT_DIR
process
.
env
.
UNI_SSR_CLIENT
=
'
true
'
await
buildByVite
({
root
:
process
.
env
.
VITE_ROOT_DIR
,
logLevel
:
options
.
logLevel
,
clearScreen
:
options
.
clearScreen
,
build
:
ssrBuildClientOptions
,
})
await
buildByVite
(
addConfigFile
({
root
:
process
.
env
.
VITE_ROOT_DIR
,
logLevel
:
options
.
logLevel
,
clearScreen
:
options
.
clearScreen
,
build
:
ssrBuildClientOptions
,
})
)
const
ssrServerDir
=
path
.
resolve
(
outputDir
,
'
server
'
)
process
.
env
.
UNI_OUTPUT_DIR
=
ssrServerDir
const
ssrBuildServerOptions
:
BuildOptions
=
cleanOptions
(
options
)
...
...
@@ -49,12 +53,14 @@ export async function buildSSR(options: CliOptions) {
}
process
.
env
.
UNI_SSR_CLIENT
=
''
process
.
env
.
UNI_SSR_SERVER
=
'
true
'
await
buildByVite
({
root
:
process
.
env
.
VITE_ROOT_DIR
,
logLevel
:
options
.
logLevel
,
clearScreen
:
options
.
clearScreen
,
build
:
ssrBuildServerOptions
,
})
await
buildByVite
(
addConfigFile
({
root
:
process
.
env
.
VITE_ROOT_DIR
,
logLevel
:
options
.
logLevel
,
clearScreen
:
options
.
clearScreen
,
build
:
ssrBuildServerOptions
,
})
)
// copy ssr-manfiest.json to server
const
assets
=
[
'
ssr-manifest.json
'
,
'
index.html
'
]
assets
.
forEach
((
asset
)
=>
{
...
...
packages/vite-plugin-uni/src/cli/server.ts
浏览文件 @
9d602447
...
...
@@ -11,15 +11,17 @@ import express from 'express'
import
{
hasOwn
}
from
'
@vue/shared
'
import
{
parseManifestJson
}
from
'
@dcloudio/uni-cli-shared
'
import
{
CliOptions
}
from
'
.
'
import
{
cleanOptions
}
from
'
./utils
'
import
{
addConfigFile
,
cleanOptions
}
from
'
./utils
'
export
async
function
createServer
(
options
:
CliOptions
&
ServerOptions
)
{
const
server
=
await
createViteServer
({
root
:
process
.
env
.
VITE_ROOT_DIR
,
logLevel
:
options
.
logLevel
,
clearScreen
:
options
.
clearScreen
,
server
:
cleanOptions
(
options
)
as
ServerOptions
,
})
const
server
=
await
createViteServer
(
addConfigFile
({
root
:
process
.
env
.
VITE_ROOT_DIR
,
logLevel
:
options
.
logLevel
,
clearScreen
:
options
.
clearScreen
,
server
:
cleanOptions
(
options
)
as
ServerOptions
,
})
)
await
server
.
listen
()
}
...
...
@@ -28,20 +30,22 @@ export async function createSSRServer(options: CliOptions & ServerOptions) {
/**
* @type {import('vite').ViteDevServer}
*/
const
vite
=
await
createViteServer
({
root
:
process
.
env
.
VITE_ROOT_DIR
,
logLevel
:
options
.
logLevel
,
clearScreen
:
options
.
clearScreen
,
server
:
{
middlewareMode
:
true
,
watch
:
{
// During tests we edit the files too fast and sometimes chokidar
// misses change events, so enforce polling for consistency
usePolling
:
true
,
interval
:
100
,
const
vite
=
await
createViteServer
(
addConfigFile
({
root
:
process
.
env
.
VITE_ROOT_DIR
,
logLevel
:
options
.
logLevel
,
clearScreen
:
options
.
clearScreen
,
server
:
{
middlewareMode
:
true
,
watch
:
{
// During tests we edit the files too fast and sometimes chokidar
// misses change events, so enforce polling for consistency
usePolling
:
true
,
interval
:
100
,
},
},
}
,
}
)
}
)
)
// use vite's connect instance as middleware
app
.
use
(
vite
.
middlewares
)
...
...
packages/vite-plugin-uni/src/cli/utils.ts
浏览文件 @
9d602447
import
fs
from
'
fs
'
import
path
from
'
path
'
import
{
BuildOptions
}
from
'
vite
'
import
{
BuildOptions
,
InlineConfig
}
from
'
vite
'
import
{
isInHBuilderX
}
from
'
@dcloudio/uni-cli-shared
'
import
{
CliOptions
}
from
'
.
'
export
const
PLATFORMS
=
[
...
...
@@ -14,6 +18,26 @@ export const PLATFORMS = [
'
quickapp-webview-union
'
,
]
function
resolveConfigFile
()
{
const
viteConfigJs
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
vite.config.js
'
)
const
viteConfigTs
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
vite.config.ts
'
)
if
(
fs
.
existsSync
(
viteConfigTs
))
{
return
viteConfigTs
}
if
(
fs
.
existsSync
(
viteConfigJs
))
{
return
viteConfigJs
}
return
path
.
resolve
(
process
.
env
.
UNI_CLI_CONTEXT
,
'
vite.config.js
'
)
}
export
function
addConfigFile
(
inlineConfig
:
InlineConfig
)
{
if
(
isInHBuilderX
())
{
inlineConfig
.
configFile
=
resolveConfigFile
()
}
return
inlineConfig
}
export
function
initEnv
(
type
:
'
dev
'
|
'
build
'
,
options
:
CliOptions
)
{
if
(
type
===
'
dev
'
)
{
process
.
env
.
NODE_ENV
=
'
development
'
...
...
@@ -25,7 +49,9 @@ export function initEnv(type: 'dev' | 'build', options: CliOptions) {
}
}
process
.
env
.
UNI_CLI_CONTEXT
=
process
.
cwd
()
// TODO HBuilderX
process
.
env
.
UNI_CLI_CONTEXT
=
isInHBuilderX
()
?
path
.
resolve
(
process
.
env
.
UNI_HBUILDERX_PLUGINS
!
,
'
uniapp-cli-vite
'
)
:
process
.
cwd
()
process
.
env
.
UNI_PLATFORM
=
options
.
platform
as
UniApp
.
PLATFORM
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录