Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
genary
uni-app
提交
2efa2ca2
U
uni-app
项目概览
genary
/
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,发现更多精彩内容 >>
提交
2efa2ca2
编写于
5月 24, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(h5): add uni.plugin.js
上级
60b42e78
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
54 addition
and
14 deletion
+54
-14
packages/uni-h5/lib/uni.plugin.js
packages/uni-h5/lib/uni.plugin.js
+13
-0
packages/uni-h5/package.json
packages/uni-h5/package.json
+4
-0
packages/vite-plugin-uni/src/config/index.ts
packages/vite-plugin-uni/src/config/index.ts
+3
-2
packages/vite-plugin-uni/src/index.ts
packages/vite-plugin-uni/src/index.ts
+11
-7
packages/vite-plugin-uni/src/utils/plugin.ts
packages/vite-plugin-uni/src/utils/plugin.ts
+1
-0
packages/vite-plugin-uni/src/vue/options.ts
packages/vite-plugin-uni/src/vue/options.ts
+20
-3
packages/vite-plugin-uni/src/vue/transforms/transformEvent.ts
...ages/vite-plugin-uni/src/vue/transforms/transformEvent.ts
+2
-2
未找到文件。
packages/uni-h5/lib/uni.plugin.js
0 → 100644
浏览文件 @
2efa2ca2
/**
* @type {import('vite').Plugin}
*/
const
UniH5Plugin
=
{
name
:
'
vite:uni-h5
'
,
uni
:
{
transformEvent
:
{
tap
:
'
click
'
,
},
},
}
module
.
exports
=
UniH5Plugin
packages/uni-h5/package.json
浏览文件 @
2efa2ca2
...
...
@@ -30,5 +30,9 @@
"peerDependencies"
:
{
"@vue/shared"
:
"^3.1.0-beta.3"
,
"vue-router"
:
"^4.0.8"
},
"uni-app"
:
{
"name"
:
"uni-h5"
,
"apply"
:
"h5"
}
}
packages/vite-plugin-uni/src/config/index.ts
浏览文件 @
2efa2ca2
...
...
@@ -25,7 +25,8 @@ function normalizeInputDir(config: UserConfig) {
return
process
.
env
.
UNI_INPUT_DIR
||
path
.
resolve
(
normalizeRoot
(
config
),
'
src
'
)
}
export
function
createConfig
(
options
:
VitePluginUniResolvedOptions
options
:
VitePluginUniResolvedOptions
,
uniPlugins
:
Plugin
[]
):
Plugin
[
'
config
'
]
{
return
(
config
,
env
)
=>
{
options
.
command
=
env
.
command
...
...
@@ -40,7 +41,7 @@ export function createConfig(
base
=
'
/
'
}
options
.
base
=
base
!
options
.
vueOptions
=
initPluginVueOptions
(
options
)
options
.
vueOptions
=
initPluginVueOptions
(
options
,
uniPlugins
)
options
.
vueJsxOptions
=
initPluginVueJsxOptions
(
options
)
options
.
viteLegacyOptions
=
initPluginViteLegacyOptions
(
options
)
...
...
packages/vite-plugin-uni/src/index.ts
浏览文件 @
2efa2ca2
import
debug
from
'
debug
'
import
{
Plugin
,
ResolvedConfig
,
ViteDevServer
}
from
'
vite
'
import
{
Options
as
VueOptions
}
from
'
@vitejs/plugin-vue
'
import
{
Options
as
ViteLegacyOptions
}
from
'
@vitejs/plugin-legacy
'
...
...
@@ -10,6 +11,9 @@ import { createConfigResolved } from './configResolved'
import
{
createConfigureServer
}
from
'
./configureServer
'
import
{
createHandleHotUpdate
}
from
'
./handleHotUpdate
'
import
{
initExtraPlugins
}
from
'
./utils
'
const
debugUni
=
debug
(
'
vite:uni:plugin
'
)
export
interface
VitePluginUniOptions
{
inputDir
?:
string
outputDir
?:
string
...
...
@@ -64,19 +68,19 @@ export default function uniPlugin(
if
(
createVueJsxPlugin
&&
options
.
vueJsxOptions
!==
false
)
{
plugins
.
push
(
createVueJsxPlugin
(
options
.
vueJsxOptions
))
}
const
uniPlugins
=
initExtraPlugins
(
process
.
env
.
UNI_CLI_CONTEXT
||
process
.
cwd
(),
(
process
.
env
.
UNI_PLATFORM
as
UniApp
.
PLATFORM
)
||
'
h5
'
)
debugUni
(
uniPlugins
)
plugins
.
push
({
name
:
'
vite:uni
'
,
config
:
createConfig
(
options
),
config
:
createConfig
(
options
,
uniPlugins
),
configResolved
:
createConfigResolved
(
options
),
configureServer
:
createConfigureServer
(
options
),
handleHotUpdate
:
createHandleHotUpdate
(
options
),
})
plugins
.
push
(
...
initExtraPlugins
(
process
.
env
.
UNI_CLI_CONTEXT
||
process
.
cwd
(),
(
process
.
env
.
UNI_PLATFORM
as
UniApp
.
PLATFORM
)
||
'
h5
'
)
)
plugins
.
push
(...
uniPlugins
)
return
plugins
}
...
...
packages/vite-plugin-uni/src/utils/plugin.ts
浏览文件 @
2efa2ca2
...
...
@@ -32,6 +32,7 @@ function initPlugin(plugin: PluginConfig): Plugin | void {
function
initPlugins
(
plugins
:
PluginConfig
[]):
Plugin
[]
{
return
plugins
.
map
((
plugin
)
=>
initPlugin
(
plugin
))
.
flat
()
.
filter
<
Plugin
>
(
Boolean
as
any
)
}
...
...
packages/vite-plugin-uni/src/vue/options.ts
浏览文件 @
2efa2ca2
import
{
Plugin
}
from
'
vite
'
import
{
extend
,
hasOwn
,
isArray
}
from
'
@vue/shared
'
import
{
SFCTemplateCompileOptions
}
from
'
@vue/compiler-sfc
'
import
{
isCustomElement
,
isNativeTag
}
from
'
@dcloudio/uni-shared
'
import
{
EXTNAME_VUE_RE
,
parseCompatConfigOnce
}
from
'
@dcloudio/uni-cli-shared
'
import
{
transformMatchMedia
}
from
'
./transforms/transformMatchMedia
'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
transformMatchMedia
}
from
'
./transforms/transformMatchMedia
'
import
{
createTransformEvent
}
from
'
./transforms/transformEvent
'
function
createUniVueTransformAssetUrls
(
...
...
@@ -31,7 +32,16 @@ function createUniVueTransformAssetUrls(
}
}
export
function
initPluginVueOptions
(
options
:
VitePluginUniResolvedOptions
)
{
interface
UniPlugin
extends
Plugin
{
uni
?:
{
transformEvent
?:
Record
<
string
,
string
>
}
}
export
function
initPluginVueOptions
(
options
:
VitePluginUniResolvedOptions
,
uniPlugins
:
UniPlugin
[]
)
{
const
vueOptions
=
options
.
vueOptions
||
(
options
.
vueOptions
=
{})
if
(
!
vueOptions
.
include
)
{
vueOptions
.
include
=
[]
...
...
@@ -61,7 +71,14 @@ export function initPluginVueOptions(options: VitePluginUniResolvedOptions) {
compatConfig
)
compilerOptions
.
nodeTransforms
.
unshift
(
createTransformEvent
({}))
const
eventOpts
=
uniPlugins
.
reduce
<
Record
<
string
,
string
>>
(
(
eventOpts
,
uniPlugin
)
=>
{
return
extend
(
eventOpts
,
uniPlugin
.
uni
?.
transformEvent
||
{})
},
{}
)
compilerOptions
.
nodeTransforms
.
unshift
(
createTransformEvent
(
eventOpts
))
if
(
options
.
platform
!==
'
mp-weixin
'
)
{
compilerOptions
.
nodeTransforms
.
unshift
(
transformMatchMedia
)
}
...
...
packages/vite-plugin-uni/src/vue/transforms/transformEvent.ts
浏览文件 @
2efa2ca2
...
...
@@ -7,8 +7,8 @@ export function createTransformEvent(options: Record<string, string>) {
return
}
node
.
props
.
forEach
((
prop
)
=>
{
const
{
arg
}
=
prop
as
DirectiveNode
if
(
arg
&&
isSimpleExpressionNode
(
arg
))
{
const
{
name
,
arg
}
=
prop
as
DirectiveNode
if
(
name
===
'
on
'
&&
arg
&&
isSimpleExpressionNode
(
arg
))
{
const
eventType
=
options
[
arg
.
content
]
if
(
eventType
)
{
// e.g tap => click
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录