Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
陈庄旺
uni-app
提交
824cf7e6
U
uni-app
项目概览
陈庄旺
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
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,发现更多精彩内容 >>
提交
824cf7e6
编写于
1月 11, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(app): nvue
上级
3fc1d5a9
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
230 addition
and
133 deletion
+230
-133
packages/shims-node.d.ts
packages/shims-node.d.ts
+1
-0
packages/uni-app-plus/__tests__/service/index.spec.ts
packages/uni-app-plus/__tests__/service/index.spec.ts
+1
-1
packages/uni-app-vite/src/index.ts
packages/uni-app-vite/src/index.ts
+6
-67
packages/uni-app-vite/src/nvue/index.ts
packages/uni-app-vite/src/nvue/index.ts
+4
-13
packages/uni-app-vite/src/nvue/plugin/index.ts
packages/uni-app-vite/src/nvue/plugin/index.ts
+15
-0
packages/uni-app-vite/src/nvue/rollup/index.ts
packages/uni-app-vite/src/nvue/rollup/index.ts
+0
-35
packages/uni-app-vite/src/vue/index.ts
packages/uni-app-vite/src/vue/index.ts
+57
-0
packages/uni-app-vite/src/vue/plugin/build.ts
packages/uni-app-vite/src/vue/plugin/build.ts
+0
-0
packages/uni-app-vite/src/vue/plugin/configResolved.ts
packages/uni-app-vite/src/vue/plugin/configResolved.ts
+0
-0
packages/uni-app-vite/src/vue/plugin/index.ts
packages/uni-app-vite/src/vue/plugin/index.ts
+0
-0
packages/uni-app-vite/src/vue/plugin/uni/index.ts
packages/uni-app-vite/src/vue/plugin/uni/index.ts
+0
-0
packages/uni-app-vite/src/vue/plugin/uni/transforms/transformRenderjs.ts
...p-vite/src/vue/plugin/uni/transforms/transformRenderjs.ts
+0
-0
packages/uni-cli-shared/src/logs/format.ts
packages/uni-cli-shared/src/logs/format.ts
+33
-1
packages/vite-plugin-uni/src/cli/build.ts
packages/vite-plugin-uni/src/cli/build.ts
+110
-14
packages/vite-plugin-uni/src/configResolved/index.ts
packages/vite-plugin-uni/src/configResolved/index.ts
+3
-2
未找到文件。
packages/shims-node.d.ts
浏览文件 @
824cf7e6
...
...
@@ -26,5 +26,6 @@ declare namespace NodeJS {
UNI_CUSTOM_DEFINE
?:
string
UNI_CUSTOM_CONTEXT
?:
string
UNI_MINIMIZE
?:
'
true
'
UNI_COMPILER
:
'
vue
'
|
'
nvue
'
}
}
packages/uni-app-plus/__tests__/service/index.spec.ts
浏览文件 @
824cf7e6
import
{
compileTemplate
}
from
'
@vue/compiler-sfc
'
import
{
uniAppPlugin
}
from
'
../../../uni-app-vite/src/plugin
'
import
{
uniAppPlugin
}
from
'
../../../uni-app-vite/src/
vue/
plugin
'
import
{
ref
,
nextTick
,
...
...
packages/uni-app-vite/src/index.ts
浏览文件 @
824cf7e6
import
{
initAppProvide
,
uniViteInjectPlugin
,
uniCssScopedPlugin
,
getAppStyleIsolation
,
parseManifestJsonOnce
,
uniHBuilderXConsolePlugin
,
UNI_EASYCOM_EXCLUDE
,
isVueSfcFile
,
isUniPageFile
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
plugins
as
nvuePlugins
}
from
'
@dcloudio/uni-cli-nvue
'
import
{
uniAppPlugin
}
from
'
./plugin
'
import
{
uniTemplatePlugin
}
from
'
./plugins/template
'
import
{
uniMainJsPlugin
}
from
'
./plugins/mainJs
'
import
{
uniManifestJsonPlugin
}
from
'
./plugins/manifestJson
'
import
{
uniPagesJsonPlugin
}
from
'
./plugins/pagesJson
'
// import { uniResolveIdPlugin } from './plugins/resolveId'
import
{
uniRenderjsPlugin
}
from
'
./plugins/renderjs
'
import
{
uniStatsPlugin
}
from
'
./plugins/stats
'
import
{
uniEasycomPlugin
}
from
'
./plugins/easycom
'
import
{
uniConfusionPlugin
}
from
'
./plugins/confusion
'
import
{
uniNVuePlugin
}
from
'
./nvue
'
import
{
uniNVueEntryPlugin
}
from
'
./nvue/plugins/entry
'
function
initUniCssScopedPluginFilter
(
inputDir
:
string
):
void
|
((
id
:
string
)
=>
boolean
)
{
const
styleIsolation
=
getAppStyleIsolation
(
parseManifestJsonOnce
(
inputDir
))
if
(
styleIsolation
===
'
shared
'
)
{
return
}
if
(
styleIsolation
===
'
isolated
'
)
{
// isolated: 对所有非 App.vue 增加 scoped
return
(
id
)
=>
isVueSfcFile
(
id
)
&&
!
id
.
endsWith
(
'
App.vue
'
)
}
// apply-shared: 仅对非页面组件增加 scoped
return
(
id
)
=>
isVueSfcFile
(
id
)
&&
!
id
.
endsWith
(
'
App.vue
'
)
&&
!
isUniPageFile
(
id
,
inputDir
)
import
{
initVuePlugins
}
from
'
./vue
'
import
{
initNVuePlugins
}
from
'
./nvue
'
export
default
()
=>
{
return
process
.
env
.
UNI_COMPILER
===
'
nvue
'
?
initNVuePlugins
()
:
initVuePlugins
()
}
const
plugins
=
[
uniEasycomPlugin
({
exclude
:
UNI_EASYCOM_EXCLUDE
}),
// uniResolveIdPlugin(),
uniHBuilderXConsolePlugin
(),
uniMainJsPlugin
(),
uniManifestJsonPlugin
(),
uniPagesJsonPlugin
(),
uniViteInjectPlugin
(
initAppProvide
()),
uniRenderjsPlugin
(),
uniTemplatePlugin
(),
uniStatsPlugin
(),
uniAppPlugin
(),
uniConfusionPlugin
(),
]
const
filter
=
initUniCssScopedPluginFilter
(
process
.
env
.
UNI_INPUT_DIR
)
if
(
filter
)
{
plugins
.
unshift
(
uniCssScopedPlugin
({
filter
}))
}
if
(
process
.
env
.
UNI_NVUE_COMPILER
===
'
vite
'
)
{
plugins
.
push
(
uniNVuePlugin
(
'
pages/demo/demo
'
))
plugins
.
push
(
uniNVueEntryPlugin
())
}
else
if
(
process
.
env
.
UNI_NVUE_COMPILER
!==
'
vue
'
)
{
plugins
.
push
(...
nvuePlugins
)
}
export
default
plugins
packages/uni-app-vite/src/nvue/index.ts
浏览文件 @
824cf7e6
import
{
Plugin
}
from
'
vite
'
import
{
createRollupOptions
}
from
'
./rollup
'
export
function
uniNVuePlugin
(
pagePath
:
string
):
Plugin
{
return
{
name
:
'
vite:uni-app-nvue
'
,
config
()
{
return
{
build
:
{
rollupOptions
:
createRollupOptions
(
pagePath
),
},
}
},
}
import
{
uniNVuePlugin
}
from
'
./plugin
'
export
function
initNVuePlugins
()
{
return
[
uniNVuePlugin
()]
}
packages/uni-app-vite/src/nvue/plugin/index.ts
0 → 100644
浏览文件 @
824cf7e6
import
path
from
'
path
'
import
{
Plugin
}
from
'
vite
'
export
function
uniNVuePlugin
():
Plugin
{
return
{
name
:
'
vite:uni-app-nvue
'
,
config
()
{
return
{
build
:
{
outDir
:
path
.
join
(
process
.
env
.
UNI_OUTPUT_DIR
,
'
../.nvue
'
),
rollupOptions
:
{},
},
}
},
}
}
packages/uni-app-vite/src/nvue/rollup/index.ts
已删除
100644 → 0
浏览文件 @
3fc1d5a9
import
{
RollupOptions
}
from
'
rollup
'
import
vue
from
'
@vitejs/plugin-vue
'
import
{
EXTNAME_VUE_RE
,
removeExt
}
from
'
@dcloudio/uni-cli-shared
'
import
{
isBuiltInComponent
}
from
'
@dcloudio/uni-shared
'
import
{
createUniNVuePagePath
}
from
'
../plugins/entry
'
export
function
createRollupOptions
(
pagePath
:
string
):
RollupOptions
{
return
{
input
:
createUniNVuePagePath
(
pagePath
),
context
:
'
global
'
,
external
:
[
'
vue
'
],
preserveEntrySignatures
:
false
,
output
:
{
dir
:
process
.
env
.
UNI_OUTPUT_DIR
,
file
:
removeExt
(
pagePath
)
+
'
.js
'
,
format
:
'
iife
'
,
exports
:
'
auto
'
,
sourcemap
:
false
,
globals
:
{
vue
:
'
Vue
'
},
},
plugins
:
[
vue
({
include
:
[
EXTNAME_VUE_RE
],
isProduction
:
process
.
env
.
NODE_ENV
===
'
production
'
,
// reactivityTransform: true,
template
:
{
compilerOptions
:
{
// TODO
isNativeTag
:
isBuiltInComponent
,
},
},
}),
],
}
}
packages/uni-app-vite/src/vue/index.ts
0 → 100644
浏览文件 @
824cf7e6
import
{
initAppProvide
,
uniViteInjectPlugin
,
uniCssScopedPlugin
,
getAppStyleIsolation
,
parseManifestJsonOnce
,
uniHBuilderXConsolePlugin
,
UNI_EASYCOM_EXCLUDE
,
isVueSfcFile
,
isUniPageFile
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
uniAppPlugin
}
from
'
../vue/plugin
'
import
{
uniTemplatePlugin
}
from
'
../plugins/template
'
import
{
uniMainJsPlugin
}
from
'
../plugins/mainJs
'
import
{
uniManifestJsonPlugin
}
from
'
../plugins/manifestJson
'
import
{
uniPagesJsonPlugin
}
from
'
../plugins/pagesJson
'
import
{
uniRenderjsPlugin
}
from
'
../plugins/renderjs
'
import
{
uniStatsPlugin
}
from
'
../plugins/stats
'
import
{
uniEasycomPlugin
}
from
'
../plugins/easycom
'
import
{
uniConfusionPlugin
}
from
'
../plugins/confusion
'
function
initUniCssScopedPluginFilter
(
inputDir
:
string
):
void
|
((
id
:
string
)
=>
boolean
)
{
const
styleIsolation
=
getAppStyleIsolation
(
parseManifestJsonOnce
(
inputDir
))
if
(
styleIsolation
===
'
shared
'
)
{
return
}
if
(
styleIsolation
===
'
isolated
'
)
{
// isolated: 对所有非 App.vue 增加 scoped
return
(
id
)
=>
isVueSfcFile
(
id
)
&&
!
id
.
endsWith
(
'
App.vue
'
)
}
// apply-shared: 仅对非页面组件增加 scoped
return
(
id
)
=>
isVueSfcFile
(
id
)
&&
!
id
.
endsWith
(
'
App.vue
'
)
&&
!
isUniPageFile
(
id
,
inputDir
)
}
export
function
initVuePlugins
()
{
const
plugins
=
[
uniEasycomPlugin
({
exclude
:
UNI_EASYCOM_EXCLUDE
}),
uniHBuilderXConsolePlugin
(),
uniMainJsPlugin
(),
uniManifestJsonPlugin
(),
uniPagesJsonPlugin
(),
uniViteInjectPlugin
(
initAppProvide
()),
uniRenderjsPlugin
(),
uniTemplatePlugin
(),
uniStatsPlugin
(),
uniAppPlugin
(),
uniConfusionPlugin
(),
]
const
filter
=
initUniCssScopedPluginFilter
(
process
.
env
.
UNI_INPUT_DIR
)
if
(
filter
)
{
plugins
.
unshift
(
uniCssScopedPlugin
({
filter
}))
}
return
plugins
}
packages/uni-app-vite/src/plugin/build.ts
→
packages/uni-app-vite/src/
vue/
plugin/build.ts
浏览文件 @
824cf7e6
文件已移动
packages/uni-app-vite/src/plugin/configResolved.ts
→
packages/uni-app-vite/src/
vue/
plugin/configResolved.ts
浏览文件 @
824cf7e6
文件已移动
packages/uni-app-vite/src/plugin/index.ts
→
packages/uni-app-vite/src/
vue/
plugin/index.ts
浏览文件 @
824cf7e6
文件已移动
packages/uni-app-vite/src/plugin/uni/index.ts
→
packages/uni-app-vite/src/
vue/
plugin/uni/index.ts
浏览文件 @
824cf7e6
文件已移动
packages/uni-app-vite/src/plugin/uni/transforms/transformRenderjs.ts
→
packages/uni-app-vite/src/
vue/
plugin/uni/transforms/transformRenderjs.ts
浏览文件 @
824cf7e6
文件已移动
packages/uni-cli-shared/src/logs/format.ts
浏览文件 @
824cf7e6
...
...
@@ -52,12 +52,44 @@ export function formatErrMsg(msg: string, options?: LogErrorOptions) {
return
msg
}
export
function
formatInfoMsg
(
msg
:
string
,
options
?:
LogOptions
)
{
const
REMOVED_NVUE_MSGS
=
[
(
msg
:
string
)
=>
{
// vite v2.7.10 building for development... (x2)
return
msg
.
includes
(
'
vite v
'
)
&&
msg
.
includes
(
'
building
'
)
},
]
export
const
removeNVueInfoFormatter
:
Formatter
=
{
test
(
msg
)
{
return
!!
REMOVED_NVUE_MSGS
.
find
((
m
)
=>
typeof
m
===
'
string
'
?
msg
.
includes
(
m
)
:
m
(
msg
)
)
},
format
()
{
return
''
},
}
const
nvueInfoFormatters
:
Formatter
[]
=
[]
const
initNVueInfoFormattersOnce
=
once
(()
=>
{
nvueInfoFormatters
.
push
(
removeNVueInfoFormatter
)
})
export
function
formatInfoMsg
(
msg
:
string
,
options
?:
LogOptions
&
{
nvue
?:
boolean
}
)
{
initInfoFormattersOnce
()
const
formatter
=
infoFormatters
.
find
(({
test
})
=>
test
(
msg
,
options
))
if
(
formatter
)
{
return
formatter
.
format
(
msg
,
options
)
}
if
(
options
?.
nvue
)
{
initNVueInfoFormattersOnce
()
const
formatter
=
nvueInfoFormatters
.
find
(({
test
})
=>
test
(
msg
,
options
))
if
(
formatter
)
{
return
formatter
.
format
(
msg
,
options
)
}
}
return
msg
}
...
...
packages/vite-plugin-uni/src/cli/build.ts
浏览文件 @
824cf7e6
import
path
from
'
path
'
import
fs
from
'
fs-extra
'
import
{
build
as
buildByVite
,
BuildOptions
,
InlineConfig
}
from
'
vite
'
import
{
build
as
buildByVite
,
BuildOptions
,
InlineConfig
,
ServerOptions
,
}
from
'
vite
'
import
{
extend
}
from
'
@vue/shared
'
import
{
initPreContext
,
...
...
@@ -10,22 +15,11 @@ import {
}
from
'
@dcloudio/uni-cli-shared
'
import
{
CliOptions
}
from
'
.
'
import
{
addConfigFile
,
cleanOptions
}
from
'
./utils
'
import
{
RollupWatcher
,
RollupWatcherEvent
}
from
'
rollup
'
export
async
function
build
(
options
:
CliOptions
)
{
if
(
options
.
platform
===
'
app
'
)
{
if
((
options
as
BuildOptions
).
manifest
)
{
return
buildManifestJson
()
}
if
(
process
.
env
.
UNI_RENDERER
===
'
native
'
)
{
return
buildByVite
(
addConfigFile
(
extend
(
{
nvue
:
true
},
initBuildOptions
(
options
,
cleanOptions
(
options
)
as
BuildOptions
)
)
)
)
}
return
buildApp
(
options
)
}
return
buildByVite
(
addConfigFile
(
...
...
@@ -99,3 +93,105 @@ function buildManifestJson() {
JSON
.
stringify
(
manifestJson
,
null
,
2
)
)
}
export
async
function
buildApp
(
options
:
CliOptions
)
{
if
((
options
as
BuildOptions
).
manifest
)
{
return
buildManifestJson
()
}
if
(
process
.
env
.
UNI_RENDERER
===
'
native
'
)
{
return
buildByVite
(
addConfigFile
(
extend
(
{
nvue
:
true
},
initBuildOptions
(
options
,
cleanOptions
(
options
)
as
BuildOptions
)
)
)
)
}
// 指定为 vue 方便 App 插件初始化 vue 所需插件列表
process
.
env
.
UNI_COMPILER
=
'
vue
'
const
vueBuilder
=
await
buildByVite
(
addConfigFile
(
initBuildOptions
(
options
,
cleanOptions
(
options
)
as
BuildOptions
)
)
)
// 临时指定为 nvue 方便 App 插件初始化 nvue 所需插件列表
process
.
env
.
UNI_COMPILER
=
'
nvue
'
const
nvueBuilder
=
await
buildByVite
(
addConfigFile
(
extend
(
{
nvue
:
true
},
initBuildOptions
(
options
,
cleanOptions
(
options
)
as
BuildOptions
)
)
)
)
// 还原为 vue
process
.
env
.
UNI_COMPILER
=
'
vue
'
if
((
options
as
ServerOptions
).
watch
)
{
return
initAppWatcher
(
vueBuilder
as
RollupWatcher
,
nvueBuilder
as
RollupWatcher
)
}
}
class
AppWatcher
{
private
_vueStart
:
boolean
=
false
private
_vueEnd
:
boolean
=
false
private
_nvueStart
:
boolean
=
false
private
_nvueEnd
:
boolean
=
false
private
_callback
!
:
(
event
:
RollupWatcherEvent
)
=>
void
on
(
callback
:
(
event
:
RollupWatcherEvent
)
=>
void
)
{
this
.
_callback
=
callback
}
_bundleVueStart
(
event
:
RollupWatcherEvent
)
{
this
.
_vueStart
=
true
this
.
_bundleStart
(
event
)
}
_bundleVueEnd
(
event
:
RollupWatcherEvent
)
{
this
.
_vueEnd
=
true
this
.
_bundleEnd
(
event
)
}
_bundleNVueStart
(
event
:
RollupWatcherEvent
)
{
this
.
_nvueStart
=
true
this
.
_bundleStart
(
event
)
}
_bundleNVueEnd
(
event
:
RollupWatcherEvent
)
{
this
.
_nvueEnd
=
true
this
.
_bundleEnd
(
event
)
}
_bundleStart
(
event
:
RollupWatcherEvent
)
{
if
(
this
.
_vueStart
&&
this
.
_nvueStart
)
{
this
.
_callback
(
event
)
}
}
_bundleEnd
(
event
:
RollupWatcherEvent
)
{
if
(
this
.
_vueEnd
&&
this
.
_nvueEnd
)
{
this
.
_callback
(
event
)
}
}
}
function
initAppWatcher
(
vueWatcher
:
RollupWatcher
,
nvueWatcher
:
RollupWatcher
)
{
const
appWatcher
=
new
AppWatcher
()
vueWatcher
.
on
(
'
event
'
,
(
event
)
=>
{
if
(
event
.
code
===
'
BUNDLE_START
'
)
{
appWatcher
.
_bundleVueStart
(
event
)
}
else
if
(
event
.
code
===
'
BUNDLE_END
'
)
{
appWatcher
.
_bundleVueEnd
(
event
)
}
})
nvueWatcher
.
on
(
'
event
'
,
(
event
)
=>
{
if
(
event
.
code
===
'
BUNDLE_START
'
)
{
appWatcher
.
_bundleNVueStart
(
event
)
}
else
if
(
event
.
code
===
'
BUNDLE_END
'
)
{
appWatcher
.
_bundleNVueEnd
(
event
)
}
})
return
{
on
(
_
,
fn
)
{
appWatcher
.
on
(
fn
as
(
event
:
RollupWatcherEvent
)
=>
void
)
},
}
as
RollupWatcher
}
packages/vite-plugin-uni/src/configResolved/index.ts
浏览文件 @
824cf7e6
import
{
Plugin
,
ResolvedConfig
}
from
'
vite
'
import
{
extend
}
from
'
@vue/shared
'
import
{
checkUpdate
,
isWindows
,
...
...
@@ -40,10 +41,10 @@ function initCheckUpdate() {
})
}
function
initLogger
({
logger
}:
ResolvedConfig
)
{
function
initLogger
({
logger
,
nvue
}:
ResolvedConfig
&
{
nvue
?:
boolean
}
)
{
const
{
info
,
warn
,
error
}
=
logger
logger
.
info
=
(
msg
,
opts
)
=>
{
msg
=
formatInfoMsg
(
msg
,
opts
)
msg
=
formatInfoMsg
(
msg
,
extend
({
nvue
},
opts
)
)
if
(
msg
)
{
return
info
(
msg
,
opts
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录