Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChenYFan_OHHH
uni-app
提交
3fd9fd21
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,发现更多精彩内容 >>
提交
3fd9fd21
编写于
1月 18, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(app): nvue
上级
0366dac7
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
226 addition
and
3 deletion
+226
-3
packages/uni-app-vite/__tests__/nvue/compiler.spec.ts
packages/uni-app-vite/__tests__/nvue/compiler.spec.ts
+74
-0
packages/uni-app-vite/src/nvue/index.ts
packages/uni-app-vite/src/nvue/index.ts
+2
-0
packages/uni-app-vite/src/nvue/plugin/index.ts
packages/uni-app-vite/src/nvue/plugin/index.ts
+24
-0
packages/uni-app-vite/src/nvue/plugin/transforms/transformAppendAsTree.ts
...-vite/src/nvue/plugin/transforms/transformAppendAsTree.ts
+31
-0
packages/uni-app-vite/src/nvue/plugin/transforms/transformRenderWhole.ts
...p-vite/src/nvue/plugin/transforms/transformRenderWhole.ts
+15
-0
packages/uni-app-vite/src/nvue/plugin/transforms/transformScrollView.ts
...pp-vite/src/nvue/plugin/transforms/transformScrollView.ts
+8
-0
packages/uni-app-vite/src/nvue/plugin/transforms/transformVideo.ts
...uni-app-vite/src/nvue/plugin/transforms/transformVideo.ts
+52
-0
packages/uni-app-vite/src/plugin/uni/index.ts
packages/uni-app-vite/src/plugin/uni/index.ts
+5
-0
packages/uni-app-vite/src/plugin/uni/transforms/transformRenderjs.ts
...i-app-vite/src/plugin/uni/transforms/transformRenderjs.ts
+0
-3
packages/uni-cli-shared/src/vue/utils.ts
packages/uni-cli-shared/src/vue/utils.ts
+15
-0
未找到文件。
packages/uni-app-vite/__tests__/nvue/compiler.spec.ts
0 → 100644
浏览文件 @
3fd9fd21
import
{
DirectiveNode
,
ElementNode
,
findDir
,
findProp
,
SimpleExpressionNode
,
}
from
'
@vue/compiler-core
'
import
{
compileTemplate
}
from
'
@vue/compiler-sfc
'
import
{
uniOptions
}
from
'
../../src/plugin/uni/index
'
process
.
env
.
UNI_COMPILER
=
'
nvue
'
const
{
compilerOptions
}
=
uniOptions
()
!
const
filename
=
'
foo.vue
'
function
compile
(
source
:
string
)
{
return
compileTemplate
({
source
,
filename
,
id
:
filename
,
compilerOptions
:
{
...
compilerOptions
,
},
}).
ast
!
.
children
[
0
]
as
ElementNode
}
describe
(
'
app-nvue: compiler
'
,
()
=>
{
test
(
'
u-tags
'
,
()
=>
{
;[
'
text
'
,
'
image
'
,
'
input
'
,
'
textarea
'
,
'
video
'
,
'
web-view
'
,
'
slider
'
,
].
forEach
((
tag
)
=>
{
expect
(
compile
(
`<
${
tag
}
></
${
tag
}
>`
).
tag
).
toBe
(
`u-
${
tag
}
`
)
})
})
test
(
'
video
'
,
()
=>
{
expect
(
compile
(
`<video></video>`
).
children
.
length
).
toBe
(
0
)
expect
(
(
compile
(
`<video><view></view></video>`
).
children
[
0
]
as
ElementNode
).
tag
).
toBe
(
'
u-scalable
'
)
})
test
(
'
scroll-view
'
,
()
=>
{
compile
(
`<view></view>`
)
})
test
(
'
render-whole
'
,
()
=>
{
expect
(
(
(
findProp
(
compile
(
`<view :render-whole="true">hello</view>`
),
'
appendAsTree
'
,
true
,
false
)
as
DirectiveNode
).
arg
as
SimpleExpressionNode
).
content
).
toBe
(
'
appendAsTree
'
)
})
test
(
'
unitary tag
'
,
()
=>
{
expect
(
findProp
(
compile
(
`<text>hello</text>`
),
'
appendAsTree
'
,
true
,
false
)
).
toBeTruthy
()
})
test
(
'
tap=>click
'
,
()
=>
{
expect
(
(
findDir
(
compile
(
`<view @tap="click"></view>`
),
'
on
'
)
!
.
arg
as
SimpleExpressionNode
).
content
).
toBe
(
'
click
'
)
})
})
packages/uni-app-vite/src/nvue/index.ts
浏览文件 @
3fd9fd21
...
@@ -13,6 +13,8 @@ import { uniEsbuildPlugin } from './plugins/esbuild'
...
@@ -13,6 +13,8 @@ import { uniEsbuildPlugin } from './plugins/esbuild'
import
{
uniMainJsPlugin
}
from
'
./plugins/mainJs
'
import
{
uniMainJsPlugin
}
from
'
./plugins/mainJs
'
import
{
uniPagesJsonPlugin
}
from
'
./plugins/pagesJson
'
import
{
uniPagesJsonPlugin
}
from
'
./plugins/pagesJson
'
export
{
initNVueNodeTransforms
}
from
'
./plugin
'
export
function
initNVuePlugins
()
{
export
function
initNVuePlugins
()
{
return
[
return
[
uniEasycomPlugin
({
exclude
:
UNI_EASYCOM_EXCLUDE
}),
uniEasycomPlugin
({
exclude
:
UNI_EASYCOM_EXCLUDE
}),
...
...
packages/uni-app-vite/src/nvue/plugin/index.ts
浏览文件 @
3fd9fd21
import
path
from
'
path
'
import
path
from
'
path
'
import
{
import
{
createTransformTag
,
dynamicImportPolyfill
,
dynamicImportPolyfill
,
normalizePath
,
normalizePath
,
parseVueRequest
,
parseVueRequest
,
...
@@ -9,6 +10,29 @@ import {
...
@@ -9,6 +10,29 @@ import {
import
{
PreRenderedChunk
}
from
'
rollup
'
import
{
PreRenderedChunk
}
from
'
rollup
'
import
{
Plugin
}
from
'
vite
'
import
{
Plugin
}
from
'
vite
'
import
{
nvueOutDir
}
from
'
../../utils
'
import
{
nvueOutDir
}
from
'
../../utils
'
import
{
transformRenderWhole
}
from
'
./transforms/transformRenderWhole
'
import
{
transformAppendAsTree
}
from
'
./transforms/transformAppendAsTree
'
import
{
transformVideo
}
from
'
./transforms/transformVideo
'
const
uTags
=
{
text
:
'
u-text
'
,
image
:
'
u-image
'
,
input
:
'
u-input
'
,
textarea
:
'
u-textarea
'
,
video
:
'
u-video
'
,
'
web-view
'
:
'
u-web-view
'
,
slider
:
'
u-slider
'
,
}
export
function
initNVueNodeTransforms
()
{
// 优先级必须确保 renderWhole > appendAsTree
return
[
createTransformTag
(
uTags
),
transformVideo
,
transformRenderWhole
,
transformAppendAsTree
,
]
}
export
function
uniAppNVuePlugin
():
Plugin
{
export
function
uniAppNVuePlugin
():
Plugin
{
return
{
return
{
name
:
'
uni:app-nvue
'
,
name
:
'
uni:app-nvue
'
,
...
...
packages/uni-app-vite/src/nvue/plugin/transforms/transformAppendAsTree.ts
0 → 100644
浏览文件 @
3fd9fd21
import
{
createBindDirectiveNode
,
isElementNode
,
renameProp
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
findProp
,
NodeTransform
}
from
'
@vue/compiler-core
'
const
unitaryTags
=
[
'
cell
'
,
'
header
'
,
'
cell-slot
'
,
'
recycle-list
'
,
'
text
'
,
'
u-text
'
,
]
export
const
transformAppendAsTree
:
NodeTransform
=
(
node
,
_
)
=>
{
if
(
!
isElementNode
(
node
))
{
return
}
// append => appendAsTree: true
const
appendProp
=
findProp
(
node
,
'
append
'
)
if
(
appendProp
)
{
renameProp
(
'
appendAsTree
'
,
appendProp
)
return
}
if
(
!
unitaryTags
.
includes
(
node
.
tag
))
{
return
}
node
.
props
.
push
(
createBindDirectiveNode
(
'
appendAsTree
'
,
'
true
'
))
}
packages/uni-app-vite/src/nvue/plugin/transforms/transformRenderWhole.ts
0 → 100644
浏览文件 @
3fd9fd21
import
{
renameProp
,
isElementNode
}
from
'
@dcloudio/uni-cli-shared
'
import
{
findProp
,
NodeTransform
}
from
'
@vue/compiler-core
'
export
const
transformRenderWhole
:
NodeTransform
=
(
node
,
_
)
=>
{
if
(
!
isElementNode
(
node
))
{
return
}
debugger
const
prop
=
findProp
(
node
,
'
render-whole
'
)
if
(
!
prop
)
{
return
}
// render-whole => append
renameProp
(
'
append
'
,
prop
)
}
packages/uni-app-vite/src/nvue/plugin/transforms/transformScrollView.ts
0 → 100644
浏览文件 @
3fd9fd21
import
{
NodeTransform
,
NodeTypes
}
from
'
@vue/compiler-core
'
export
const
transformScrollView
:
NodeTransform
=
(
node
,
context
)
=>
{
if
(
node
.
type
!==
NodeTypes
.
ROOT
)
{
return
}
console
.
log
(
context
)
}
packages/uni-app-vite/src/nvue/plugin/transforms/transformVideo.ts
0 → 100644
浏览文件 @
3fd9fd21
import
{
createBindDirectiveNode
,
isElementNode
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
createSimpleExpression
,
ElementNode
,
ElementTypes
,
NodeTransform
,
NodeTypes
,
}
from
'
@vue/compiler-core
'
function
isVideo
(
node
:
ElementNode
)
{
return
node
.
tag
===
'
video
'
||
node
.
tag
===
'
u-video
'
}
export
const
transformVideo
:
NodeTransform
=
(
node
,
_
)
=>
{
if
(
!
isElementNode
(
node
))
{
return
}
if
(
!
isVideo
(
node
))
{
return
}
if
(
!
node
.
children
.
length
)
{
return
}
const
firstChild
=
node
.
children
[
0
]
if
(
isElementNode
(
firstChild
)
&&
firstChild
.
tag
===
'
u-scalable
'
)
{
return
}
node
.
children
=
[
createScalable
(
node
)]
}
function
createScalable
(
node
:
ElementNode
):
ElementNode
{
return
{
tag
:
'
u-scalable
'
,
type
:
NodeTypes
.
ELEMENT
,
tagType
:
ElementTypes
.
ELEMENT
,
props
:
[
createBindDirectiveNode
(
'
style
'
,
createSimpleExpression
(
'
{position:"absolute",left:"0",right:"0",top:"0",bottom:"0"}
'
)
),
],
isSelfClosing
:
true
,
children
:
node
.
children
,
codegenNode
:
undefined
,
ns
:
node
.
ns
,
loc
:
node
.
loc
,
}
}
packages/uni-app-vite/src/plugin/uni/index.ts
浏览文件 @
3fd9fd21
...
@@ -9,6 +9,8 @@ import {
...
@@ -9,6 +9,8 @@ import {
UniViteCopyPluginOptions
,
UniViteCopyPluginOptions
,
}
from
'
@dcloudio/uni-cli-shared
'
}
from
'
@dcloudio/uni-cli-shared
'
import
{
initNVueNodeTransforms
}
from
'
../../nvue
'
export
function
uniOptions
():
UniVitePlugin
[
'
uni
'
]
{
export
function
uniOptions
():
UniVitePlugin
[
'
uni
'
]
{
return
{
return
{
copyOptions
()
{
copyOptions
()
{
...
@@ -38,6 +40,9 @@ export function uniOptions(): UniVitePlugin['uni'] {
...
@@ -38,6 +40,9 @@ export function uniOptions(): UniVitePlugin['uni'] {
compilerOptions
:
{
compilerOptions
:
{
isNativeTag
,
isNativeTag
,
nodeTransforms
:
[
nodeTransforms
:
[
...(
process
.
env
.
UNI_COMPILER
===
'
nvue
'
?
initNVueNodeTransforms
()
:
[]),
transformTapToClick
,
transformTapToClick
,
transformMatchMedia
,
transformMatchMedia
,
transformPageHead
,
transformPageHead
,
...
...
packages/uni-app-vite/src/plugin/uni/transforms/transformRenderjs.ts
已删除
100644 → 0
浏览文件 @
0366dac7
import
type
{
NodeTransform
}
from
'
@vue/compiler-core
'
export
const
transformRenderjs
:
NodeTransform
=
()
=>
{}
packages/uni-cli-shared/src/vue/utils.ts
浏览文件 @
3fd9fd21
...
@@ -14,9 +14,11 @@ import {
...
@@ -14,9 +14,11 @@ import {
ExpressionNode
,
ExpressionNode
,
TemplateChildNode
,
TemplateChildNode
,
TransformContext
,
TransformContext
,
isStaticExp
,
}
from
'
@vue/compiler-core
'
}
from
'
@vue/compiler-core
'
import
{
createAssetUrlTransformWithOptions
}
from
'
./transforms/templateTransformAssetUrl
'
import
{
createAssetUrlTransformWithOptions
}
from
'
./transforms/templateTransformAssetUrl
'
import
{
createSrcsetTransformWithOptions
}
from
'
./transforms/templateTransformSrcset
'
import
{
createSrcsetTransformWithOptions
}
from
'
./transforms/templateTransformSrcset
'
import
{
isDirectiveNode
}
from
'
../vite/utils/ast
'
import
{
parseVueRequest
}
from
'
../vite/utils/url
'
import
{
parseVueRequest
}
from
'
../vite/utils/url
'
import
{
EXTNAME_VUE_RE
}
from
'
../constants
'
import
{
EXTNAME_VUE_RE
}
from
'
../constants
'
...
@@ -137,3 +139,16 @@ export function getBaseNodeTransforms(base: string) {
...
@@ -137,3 +139,16 @@ export function getBaseNodeTransforms(base: string) {
createSrcsetTransformWithOptions
(
transformAssetUrls
),
createSrcsetTransformWithOptions
(
transformAssetUrls
),
]
]
}
}
export
function
renameProp
(
name
:
string
,
prop
?:
DirectiveNode
|
AttributeNode
)
{
if
(
!
prop
)
{
return
}
if
(
isDirectiveNode
(
prop
))
{
if
(
prop
.
arg
&&
isStaticExp
(
prop
.
arg
))
{
prop
.
arg
.
content
=
name
}
}
else
{
prop
.
name
=
name
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录