Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChenYFan_OHHH
uni-app
提交
5df88a23
U
uni-app
项目概览
ChenYFan_OHHH
/
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,发现更多精彩内容 >>
提交
5df88a23
编写于
2月 14, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(app): nvue
上级
3d2d1efc
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
128 addition
and
50 deletion
+128
-50
packages/shims-node.d.ts
packages/shims-node.d.ts
+1
-0
packages/uni-app-vite/src/index.ts
packages/uni-app-vite/src/index.ts
+1
-1
packages/uni-app-vite/src/nvue/index.ts
packages/uni-app-vite/src/nvue/index.ts
+4
-3
packages/uni-app-vite/src/nvue/plugin/index.ts
packages/uni-app-vite/src/nvue/plugin/index.ts
+6
-10
packages/uni-app-vite/src/nvue/plugins/esbuild.ts
packages/uni-app-vite/src/nvue/plugins/esbuild.ts
+43
-5
packages/uni-app-vite/src/nvue/plugins/mainJs.ts
packages/uni-app-vite/src/nvue/plugins/mainJs.ts
+5
-3
packages/uni-app-vite/src/nvue/plugins/pagesJson.ts
packages/uni-app-vite/src/nvue/plugins/pagesJson.ts
+6
-2
packages/uni-app-vite/src/plugin/build.ts
packages/uni-app-vite/src/plugin/build.ts
+14
-2
packages/uni-app-vite/src/plugin/index.ts
packages/uni-app-vite/src/plugin/index.ts
+6
-2
packages/vite-plugin-uni/src/cli/build.ts
packages/vite-plugin-uni/src/cli/build.ts
+42
-22
未找到文件。
packages/shims-node.d.ts
浏览文件 @
5df88a23
...
...
@@ -27,5 +27,6 @@ declare namespace NodeJS {
UNI_CUSTOM_CONTEXT
?:
string
UNI_MINIMIZE
?:
'
true
'
UNI_COMPILER
:
'
vue
'
|
'
nvue
'
UNI_COMPILER_NVUE
:
'
app
'
|
'
page
'
}
}
packages/uni-app-vite/src/index.ts
浏览文件 @
5df88a23
...
...
@@ -3,7 +3,7 @@ import { initNVuePlugins } from './nvue'
import
{
uniAppPlugin
}
from
'
./plugin
'
export
default
()
=>
{
return
[
uniAppPlugin
(),
uniAppPlugin
(
{
renderer
:
process
.
env
.
UNI_RENDERER
}
),
...(
process
.
env
.
UNI_COMPILER
===
'
nvue
'
?
initNVuePlugins
()
:
initVuePlugins
()),
...
...
packages/uni-app-vite/src/nvue/index.ts
浏览文件 @
5df88a23
...
...
@@ -17,16 +17,17 @@ import { uniPagesJsonPlugin } from './plugins/pagesJson'
export
{
initNVueNodeTransforms
}
from
'
./plugin
'
export
function
initNVuePlugins
()
{
const
renderer
=
process
.
env
.
UNI_RENDERER
return
[
uniAppCssPlugin
(),
uniEasycomPlugin
({
exclude
:
UNI_EASYCOM_EXCLUDE
}),
uniHBuilderXConsolePlugin
(),
uniMainJsPlugin
(),
uniMainJsPlugin
(
{
renderer
}
),
...(
process
.
env
.
UNI_RENDERER
===
'
native
'
?
[
uniManifestJsonPlugin
()]
:
[]),
uniPagesJsonPlugin
(),
uniPagesJsonPlugin
(
{
renderer
}
),
uniViteInjectPlugin
(
'
uni:app-inject
'
,
initAppProvide
()),
uniStatsPlugin
(),
uniAppNVuePlugin
(),
uniEsbuildPlugin
(),
uniEsbuildPlugin
(
{
renderer
}
),
]
}
packages/uni-app-vite/src/nvue/plugin/index.ts
浏览文件 @
5df88a23
...
...
@@ -52,12 +52,6 @@ export function uniAppNVuePlugin(): Plugin {
name
:
'
uni:app-nvue
'
,
config
()
{
return
{
lib
:
{
// 必须使用 lib 模式,否则会生成 preload 等代码
fileName
:
'
main.js
'
,
entry
:
mainPath
,
formats
:
[
'
esm
'
],
},
css
:
{
postcss
:
{
plugins
:
initPostcssPlugin
({
...
...
@@ -67,12 +61,15 @@ export function uniAppNVuePlugin(): Plugin {
},
},
build
:
{
lib
:
{
// 必须使用 lib 模式,否则会生成 preload 等代码
fileName
:
'
app
'
,
entry
:
mainPath
,
formats
:
[
'
es
'
],
},
outDir
:
nvueOutDir
(),
rollupOptions
:
{
external
,
input
:
{
main
:
mainPath
,
},
output
:
{
entryFileNames
(
chunk
)
{
if
(
chunk
.
name
===
'
main
'
)
{
...
...
@@ -80,7 +77,6 @@ export function uniAppNVuePlugin(): Plugin {
}
return
chunk
.
name
+
'
.js
'
},
format
:
'
esm
'
,
assetFileNames
:
'
[name][extname]
'
,
chunkFileNames
:
createChunkFileNames
(
inputDir
),
plugins
:
[
dynamicImportPolyfill
()],
...
...
packages/uni-app-vite/src/nvue/plugins/esbuild.ts
浏览文件 @
5df88a23
...
...
@@ -5,14 +5,22 @@ import path from 'path'
import
fs
from
'
fs-extra
'
import
debug
from
'
debug
'
import
{
transformWithEsbuild
}
from
'
@dcloudio/uni-cli-shared
'
import
{
APP_SERVICE_FILENAME
,
transformWithEsbuild
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
nvueOutDir
}
from
'
../../utils
'
import
{
esbuildGlobals
}
from
'
../utils
'
import
{
APP_CSS_JS
}
from
'
./appCss
'
const
debugEsbuild
=
debug
(
'
uni:app-nvue-esbuild
'
)
export
function
uniEsbuildPlugin
():
Plugin
{
export
function
uniEsbuildPlugin
({
renderer
,
}:
{
renderer
?:
'
native
'
}):
Plugin
{
let
buildOptions
:
BuildOptions
const
outputDir
=
process
.
env
.
UNI_OUTPUT_DIR
return
{
...
...
@@ -42,9 +50,18 @@ export function uniEsbuildPlugin(): Plugin {
entryPoints
.
push
(
name
)
}
})
if
(
renderer
===
'
native
'
)
{
debugEsbuild
(
'
start
'
,
APP_SERVICE_FILENAME
)
await
buildNVueAppService
(
buildOptions
).
then
((
code
)
=>
{
return
fs
.
outputFile
(
path
.
resolve
(
outputDir
,
APP_SERVICE_FILENAME
),
code
)
})
}
debugEsbuild
(
'
start
'
,
entryPoints
.
length
,
entryPoints
)
for
(
const
filename
of
entryPoints
)
{
await
buildNVuePage
(
filename
,
buildOptions
).
then
((
code
)
=>
{
await
buildNVuePage
(
renderer
,
filename
,
buildOptions
).
then
((
code
)
=>
{
return
fs
.
outputFile
(
path
.
resolve
(
outputDir
,
filename
),
code
)
})
}
...
...
@@ -53,10 +70,31 @@ export function uniEsbuildPlugin(): Plugin {
}
}
function
buildNVuePage
(
filename
:
string
,
options
:
BuildOptions
)
{
function
buildNVueAppService
(
options
:
BuildOptions
)
{
return
transformWithEsbuild
(
`import './app.js'`
,
path
.
join
(
nvueOutDir
(),
'
main.js
'
),
options
).
then
((
res
)
=>
{
if
(
res
.
outputFiles
)
{
return
res
.
outputFiles
[
0
].
text
}
return
''
})
}
function
buildNVuePage
(
renderer
:
'
native
'
|
undefined
,
filename
:
string
,
options
:
BuildOptions
)
{
return
transformWithEsbuild
(
`import App from './
${
filename
}
'
import { AppStyles } from './app.css.js'
${
renderer
===
'
native
'
?
'
const AppStyles = __uniConfig.appStyles || []
'
:
`import { AppStyles } from '
${
APP_CSS_JS
}
'`
}
const webview = plus.webview.currentWebview()
const __pageId = parseInt(webview.id)
const __pagePath = webview.__path__
...
...
packages/uni-app-vite/src/nvue/plugins/mainJs.ts
浏览文件 @
5df88a23
import
{
defineUniMainJsPlugin
,
PAGES_JSON_JS
}
from
'
@dcloudio/uni-cli-shared
'
import
{
APP_CSS_JS
}
from
'
./appCss
'
export
function
uniMainJsPlugin
()
{
export
function
uniMainJsPlugin
(
{
renderer
}:
{
renderer
?:
'
native
'
}
)
{
return
defineUniMainJsPlugin
((
opts
)
=>
{
return
{
name
:
'
uni:app-nvue-main-js
'
,
enforce
:
'
pre
'
,
transform
(
code
,
id
)
{
if
(
opts
.
filter
(
id
))
{
if
(
process
.
env
.
UNI_RENDERER
===
'
native
'
)
{
if
(
renderer
===
'
native
'
)
{
code
=
code
.
includes
(
'
createSSRApp
'
)
?
createApp
(
code
)
:
createLegacyApp
(
code
)
return
{
code
:
`import './
${
PAGES_JSON_JS
}
';`
+
code
,
code
:
`import './
${
PAGES_JSON_JS
}
';import('
${
APP_CSS_JS
}
').then(()=>{});`
+
code
,
map
:
{
mappings
:
''
},
}
}
...
...
packages/uni-app-vite/src/nvue/plugins/pagesJson.ts
浏览文件 @
5df88a23
...
...
@@ -11,7 +11,11 @@ import {
MANIFEST_JSON_JS
,
}
from
'
@dcloudio/uni-cli-shared
'
export
function
uniPagesJsonPlugin
():
Plugin
{
export
function
uniPagesJsonPlugin
({
renderer
,
}:
{
renderer
?:
'
native
'
}):
Plugin
{
return
defineUniPagesJsonPlugin
((
opts
)
=>
{
return
{
name
:
'
uni:app-nvue-pages-json
'
,
...
...
@@ -34,7 +38,7 @@ export function uniPagesJsonPlugin(): Plugin {
)
}
})
if
(
process
.
env
.
UNI_RENDERER
===
'
native
'
)
{
if
(
renderer
===
'
native
'
)
{
this
.
emitFile
({
fileName
:
`app-config-service.js`
,
type
:
'
asset
'
,
...
...
packages/uni-app-vite/src/plugin/build.ts
浏览文件 @
5df88a23
...
...
@@ -11,22 +11,34 @@ import {
import
{
nvueOutDir
}
from
'
../utils
'
export
function
buildOptions
(
renderer
:
'
native
'
|
undefined
,
userConfig
:
UserConfig
,
_
:
ConfigEnv
):
UserConfig
[
'
build
'
]
{
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
const
outputDir
=
process
.
env
.
UNI_OUTPUT_DIR
// 开始编译时,清空输出目录
if
(
isInHybridNVue
(
userConfig
)
)
{
function
emptyNVueDir
(
)
{
const
nvueOutputDir
=
nvueOutDir
()
if
(
fs
.
existsSync
(
nvueOutputDir
))
{
emptyDir
(
nvueOutputDir
)
}
}
else
{
}
function
emptyOutDir
()
{
if
(
fs
.
existsSync
(
outputDir
))
{
emptyDir
(
outputDir
)
}
}
if
(
renderer
===
'
native
'
)
{
emptyNVueDir
()
emptyOutDir
()
}
else
{
if
(
isInHybridNVue
(
userConfig
))
{
emptyNVueDir
()
}
else
{
emptyOutDir
()
}
}
return
{
// App 端目前仅提供 inline
sourcemap
:
userConfig
.
build
?.
sourcemap
?
'
inline
'
:
false
,
...
...
packages/uni-app-vite/src/plugin/index.ts
浏览文件 @
5df88a23
...
...
@@ -3,13 +3,17 @@ import { UniVitePlugin } from '@dcloudio/uni-cli-shared'
import
{
uniOptions
}
from
'
./uni
'
import
{
buildOptions
}
from
'
./build
'
export
function
uniAppPlugin
():
UniVitePlugin
{
export
function
uniAppPlugin
({
renderer
,
}:
{
renderer
?:
'
native
'
}
=
{}):
UniVitePlugin
{
return
{
name
:
'
uni:app
'
,
uni
:
uniOptions
(),
config
(
config
,
env
)
{
return
{
build
:
buildOptions
(
config
,
env
),
build
:
buildOptions
(
renderer
,
config
,
env
),
}
},
}
...
...
packages/vite-plugin-uni/src/cli/build.ts
浏览文件 @
5df88a23
...
...
@@ -99,8 +99,19 @@ export async function buildApp(options: CliOptions) {
return
buildManifestJson
()
}
if
(
process
.
env
.
UNI_RENDERER
===
'
native
'
)
{
// 纯原生渲染时,main.js + App.vue 需要跟页面分开,独立编译(因为需要包含 Vuex 等共享内容)
process
.
env
.
UNI_COMPILER
=
'
nvue
'
return
buildByVite
(
process
.
env
.
UNI_COMPILER_NVUE
=
'
app
'
const
nvueAppBuilder
=
await
buildByVite
(
addConfigFile
(
extend
(
{
nvueApp
:
true
,
nvue
:
true
},
initBuildOptions
(
options
,
cleanOptions
(
options
)
as
BuildOptions
)
)
)
)
process
.
env
.
UNI_COMPILER_NVUE
=
'
page
'
const
nvueBuilder
=
await
buildByVite
(
addConfigFile
(
extend
(
{
nvue
:
true
},
...
...
@@ -108,6 +119,12 @@ export async function buildApp(options: CliOptions) {
)
)
)
if
((
options
as
ServerOptions
).
watch
)
{
return
initAppWatcher
(
nvueAppBuilder
as
RollupWatcher
,
nvueBuilder
as
RollupWatcher
)
}
}
// 指定为 vue 方便 App 插件初始化 vue 所需插件列表
process
.
env
.
UNI_COMPILER
=
'
vue
'
...
...
@@ -138,56 +155,59 @@ export async function buildApp(options: CliOptions) {
}
class
AppWatcher
{
private
_
vue
Start
:
boolean
=
false
private
_
vue
End
:
boolean
=
false
private
_
nvue
Start
:
boolean
=
false
private
_
nvue
End
:
boolean
=
false
private
_
first
Start
:
boolean
=
false
private
_
first
End
:
boolean
=
false
private
_
second
Start
:
boolean
=
false
private
_
second
End
:
boolean
=
false
private
_callback
!
:
(
event
:
RollupWatcherEvent
)
=>
void
on
(
callback
:
(
event
:
RollupWatcherEvent
)
=>
void
)
{
this
.
_callback
=
callback
}
_bundle
Vue
Start
(
event
:
RollupWatcherEvent
)
{
this
.
_
vue
Start
=
true
_bundle
First
Start
(
event
:
RollupWatcherEvent
)
{
this
.
_
first
Start
=
true
this
.
_bundleStart
(
event
)
}
_bundle
Vue
End
(
event
:
RollupWatcherEvent
)
{
this
.
_
vue
End
=
true
_bundle
First
End
(
event
:
RollupWatcherEvent
)
{
this
.
_
first
End
=
true
this
.
_bundleEnd
(
event
)
}
_bundle
NVue
Start
(
event
:
RollupWatcherEvent
)
{
this
.
_
nvue
Start
=
true
_bundle
Second
Start
(
event
:
RollupWatcherEvent
)
{
this
.
_
second
Start
=
true
this
.
_bundleStart
(
event
)
}
_bundle
NVue
End
(
event
:
RollupWatcherEvent
)
{
this
.
_
nvue
End
=
true
_bundle
Second
End
(
event
:
RollupWatcherEvent
)
{
this
.
_
second
End
=
true
this
.
_bundleEnd
(
event
)
}
_bundleStart
(
event
:
RollupWatcherEvent
)
{
if
(
this
.
_
vueStart
&&
this
.
_nvue
Start
)
{
if
(
this
.
_
firstStart
&&
this
.
_second
Start
)
{
this
.
_callback
(
event
)
}
}
_bundleEnd
(
event
:
RollupWatcherEvent
)
{
if
(
this
.
_
vueEnd
&&
this
.
_nvue
End
)
{
if
(
this
.
_
firstEnd
&&
this
.
_second
End
)
{
this
.
_callback
(
event
)
}
}
}
function
initAppWatcher
(
vueWatcher
:
RollupWatcher
,
nvueWatcher
:
RollupWatcher
)
{
function
initAppWatcher
(
firstWatcher
:
RollupWatcher
,
secondWatcher
:
RollupWatcher
)
{
const
appWatcher
=
new
AppWatcher
()
vue
Watcher
.
on
(
'
event
'
,
(
event
)
=>
{
first
Watcher
.
on
(
'
event
'
,
(
event
)
=>
{
if
(
event
.
code
===
'
BUNDLE_START
'
)
{
appWatcher
.
_bundle
Vue
Start
(
event
)
appWatcher
.
_bundle
First
Start
(
event
)
}
else
if
(
event
.
code
===
'
BUNDLE_END
'
)
{
appWatcher
.
_bundle
Vue
End
(
event
)
appWatcher
.
_bundle
First
End
(
event
)
}
})
nvue
Watcher
.
on
(
'
event
'
,
(
event
)
=>
{
second
Watcher
.
on
(
'
event
'
,
(
event
)
=>
{
if
(
event
.
code
===
'
BUNDLE_START
'
)
{
appWatcher
.
_bundle
NVue
Start
(
event
)
appWatcher
.
_bundle
Second
Start
(
event
)
}
else
if
(
event
.
code
===
'
BUNDLE_END
'
)
{
appWatcher
.
_bundle
NVue
End
(
event
)
appWatcher
.
_bundle
Second
End
(
event
)
}
})
return
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录