Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
4994f182
U
uni-app
项目概览
qianlong66
/
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,发现更多精彩内容 >>
提交
4994f182
编写于
12月 18, 2020
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(easycom): add watch
上级
aae1338f
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
80 addition
and
37 deletion
+80
-37
packages/uni-cli-shared/src/easycom/autoImport.ts
packages/uni-cli-shared/src/easycom/autoImport.ts
+0
-18
packages/uni-cli-shared/src/easycom/index.ts
packages/uni-cli-shared/src/easycom/index.ts
+28
-0
packages/uni-cli-shared/src/index.ts
packages/uni-cli-shared/src/index.ts
+1
-2
packages/uni-cli-shared/src/transforms/transformBuiltInComponent.ts
...ni-cli-shared/src/transforms/transformBuiltInComponent.ts
+3
-3
packages/uni-cli-shared/src/transforms/transformBuiltInEasycom.ts
.../uni-cli-shared/src/transforms/transformBuiltInEasycom.ts
+1
-1
packages/uni-cli-shared/src/transforms/transformEasycom.ts
packages/uni-cli-shared/src/transforms/transformEasycom.ts
+11
-4
packages/uni-cli-shared/src/vueCompilerOptions.ts
packages/uni-cli-shared/src/vueCompilerOptions.ts
+12
-2
packages/vite-plugin-uni/package.json
packages/vite-plugin-uni/package.json
+1
-2
packages/vite-plugin-uni/src/index.ts
packages/vite-plugin-uni/src/index.ts
+8
-0
packages/vite-plugin-uni/src/server/serverPluginEnv.ts
packages/vite-plugin-uni/src/server/serverPluginEnv.ts
+15
-5
未找到文件。
packages/uni-cli-shared/src/
transforms
/autoImport.ts
→
packages/uni-cli-shared/src/
easycom
/autoImport.ts
浏览文件 @
4994f182
import
{
ComponentNode
,
ElementNode
,
ElementTypes
,
ExpressionNode
,
RootNode
,
SimpleExpressionNode
,
TemplateChildNode
,
TransformContext
}
from
'
@vue/compiler-core
'
...
...
@@ -14,18 +9,10 @@ interface ImportItem {
path
:
string
}
const
tags
=
new
Set
<
string
>
()
export
function
isAutoImported
(
tag
:
string
)
{
return
tags
.
has
(
tag
)
}
export
function
addAutoImport
(
tag
:
string
,
importItem
:
ImportItem
,
context
:
TransformContext
)
{
tag
&&
tags
.
add
(
tag
)
const
importPath
=
importItem
.
path
const
importContent
=
(
importItem
.
exp
as
SimpleExpressionNode
).
content
const
importsArray
=
Array
.
from
(
context
.
imports
)
...
...
@@ -40,8 +27,3 @@ export function addAutoImport(
context
.
imports
.
add
(
importItem
)
return
true
}
export
const
isComponentNode
=
(
node
:
RootNode
|
TemplateChildNode
):
node
is
ComponentNode
=>
(
node
as
ElementNode
).
tagType
===
ElementTypes
.
COMPONENT
packages/uni-cli-shared/src/easycom.ts
→
packages/uni-cli-shared/src/easycom
/index
.ts
浏览文件 @
4994f182
import
fs
from
'
fs
'
import
path
from
'
path
'
import
debug
from
'
debug
'
import
{
RootNode
,
ElementNode
,
ElementTypes
,
ComponentNode
,
TemplateChildNode
}
from
'
@vue/compiler-core
'
interface
EasycomOption
{
dirs
?:
string
[]
rootDir
?:
string
...
...
@@ -15,6 +24,8 @@ interface EasycomCustom {
[
key
:
string
]:
string
}
export
*
from
'
./autoImport
'
export
const
debugEasycom
=
debug
(
'
easycom
'
)
const
easycoms
:
EasycomMatcher
[]
=
[]
...
...
@@ -26,10 +37,27 @@ let hasEasycom = false
function
clearEasycom
()
{
easycoms
.
length
=
0
tags
.
clear
()
easycomsCache
.
clear
()
easycomsInvalidCache
.
clear
()
}
const
tags
=
new
Set
<
string
>
()
export
function
isEasycomTag
(
tag
:
string
)
{
return
tags
.
has
(
tag
)
}
export
function
addEasycomTag
(
tag
:
string
)
{
return
tags
.
add
(
tag
)
}
export
const
isComponentNode
=
(
node
:
RootNode
|
TemplateChildNode
):
node
is
ComponentNode
=>
(
node
as
ElementNode
).
tagType
===
ElementTypes
.
COMPONENT
export
function
initEasycom
({
dirs
,
rootDir
,
...
...
packages/uni-cli-shared/src/index.ts
浏览文件 @
4994f182
export
*
from
'
./json
'
export
*
from
'
./easycom
'
export
*
from
'
./easycom
/index
'
export
*
from
'
./vueCompilerOptions
'
export
*
from
'
./transforms/transformBuiltInComponent
'
export
*
from
'
./transforms/transformBuiltInEasycom
'
export
*
from
'
./transforms/transformEasycom
'
export
{
isAutoImported
}
from
'
./transforms/autoImport
'
packages/uni-cli-shared/src/transforms/transformBuiltInComponent.ts
浏览文件 @
4994f182
...
...
@@ -10,7 +10,7 @@ import {
import
{
COMPONENT_PREFIX
,
isBuiltInComponent
}
from
'
@dcloudio/uni-shared
'
import
{
addAutoImport
,
isComponentNode
}
from
'
.
/autoImport
'
import
{
addAutoImport
,
isComponentNode
}
from
'
.
./easycom
'
const
COMPONENTS_PATH
=
'
@dcloudio/uni-h5/dist/uni-h5.esm.js
'
...
...
@@ -52,7 +52,7 @@ export const transformBuiltInComponent: NodeTransform = (node, context) => {
return
}
node
.
tag
=
COMPONENT_PREFIX
+
tag
if
(
addAutoImport
(
node
.
tag
,
createComponentImportItem
(
tag
,
node
),
context
))
{
addAutoImport
(
''
,
createStyleImportItem
(
tag
,
node
),
context
)
if
(
addAutoImport
(
createComponentImportItem
(
tag
,
node
),
context
))
{
addAutoImport
(
createStyleImportItem
(
tag
,
node
),
context
)
}
}
packages/uni-cli-shared/src/transforms/transformBuiltInEasycom.ts
浏览文件 @
4994f182
import
{
NodeTransform
}
from
'
@vue/compiler-core
'
import
{
isComponentNode
}
from
'
.
/autoImport
'
import
{
isComponentNode
}
from
'
.
./easycom/index
'
export
const
transformBuiltInEasycom
:
NodeTransform
=
node
=>
{
if
(
!
isComponentNode
(
node
))
{
...
...
packages/uni-cli-shared/src/transforms/transformEasycom.ts
浏览文件 @
4994f182
...
...
@@ -10,9 +10,13 @@ import {
import
{
COMPONENT_PREFIX
}
from
'
@dcloudio/uni-shared
'
import
{
debugEasycom
,
matchEasycom
}
from
'
../easycom
'
import
{
addAutoImport
,
isComponentNode
}
from
'
./autoImport
'
import
{
addEasycomTag
,
debugEasycom
,
matchEasycom
,
addAutoImport
,
isComponentNode
}
from
'
../easycom
'
function
createImportItem
(
path
:
string
,
node
:
ComponentNode
)
{
const
tag
=
node
.
tag
...
...
@@ -60,5 +64,8 @@ export const transformEasycom: NodeTransform = (node, context) => {
return
debugEasycom
(
tag
+
'
is binding by setup
'
)
}
const
path
=
matchEasycom
(
tag
)
path
&&
addAutoImport
(
tag
,
createImportItem
(
path
,
node
),
context
)
if
(
path
)
{
addEasycomTag
(
tag
)
addAutoImport
(
createImportItem
(
path
,
node
),
context
)
}
}
packages/uni-cli-shared/src/vueCompilerOptions.ts
浏览文件 @
4994f182
import
{
CompilerOptions
}
from
'
@vue/compiler-sfc
'
import
{
isNativeTag
}
from
'
@dcloudio/uni-shared
'
import
{
COMPONENT_PREFIX
,
isBuiltInComponent
,
isNativeTag
}
from
'
@dcloudio/uni-shared
'
import
{
isAutoImported
}
from
'
./transforms/autoImport
'
import
{
transformBuiltInComponent
}
from
'
./transforms/transformBuiltInComponent
'
import
{
transformBuiltInEasycom
}
from
'
./transforms/transformBuiltInEasycom
'
import
{
transformEasycom
}
from
'
./transforms/transformEasycom
'
import
{
isEasycomTag
}
from
'
./easycom
'
interface
CodegenContext
{
push
:
(
code
:
string
,
node
:
any
)
=>
void
...
...
@@ -15,6 +19,12 @@ interface VueCompilerOptions extends CompilerOptions {
onContextCreated
:
(
context
:
CodegenContext
)
=>
void
}
function
isAutoImported
(
tag
:
string
)
{
return
(
isEasycomTag
(
tag
)
||
isBuiltInComponent
(
tag
.
replace
(
COMPONENT_PREFIX
,
''
))
)
}
const
resolveComponentRE
=
/_resolveComponent
\(
"
(
.*
)
"
\)
/
export
const
vueCompilerOptions
:
VueCompilerOptions
=
{
onContextCreated
(
context
)
{
...
...
packages/vite-plugin-uni/package.json
浏览文件 @
4994f182
...
...
@@ -23,8 +23,7 @@
"dependencies"
:
{
"@rollup/pluginutils"
:
"^4.1.0"
,
"estree-walker"
:
"^2.0.1"
,
"magic-string"
:
"^0.25.7"
,
"slash"
:
"^3.0.0"
"magic-string"
:
"^0.25.7"
},
"peerDependencies"
:
{
"@dcloudio/uni-cli-shared"
:
"^3.0.0"
,
...
...
packages/vite-plugin-uni/src/index.ts
浏览文件 @
4994f182
...
...
@@ -57,6 +57,14 @@ Object.assign(plugin, {
'
@dcloudio/uni-h5-vue
'
,
'
@dcloudio/uni-shared
'
]
},
chokidarWatchOptions
:
{
ignored
:
[
'
**/node_modules/**
'
,
'
**/.git/**
'
,
'
**/uniCloud-aliyun/**
'
,
'
**/uniCloud-tcb/**
'
]
}
})
export
default
plugin
packages/vite-plugin-uni/src/server/serverPluginEnv.ts
浏览文件 @
4994f182
...
...
@@ -4,9 +4,19 @@ import { ServerPlugin } from 'vite'
import
{
initEasycom
}
from
'
@dcloudio/uni-cli-shared
'
export
const
serverPluginEnv
:
ServerPlugin
=
({
root
})
=>
{
if
(
process
.
env
.
UNI_INPUT_DIR
)
{
process
.
env
.
UNI_INPUT_DIR
=
path
.
resolve
(
root
,
'
src
'
)
}
initEasycom
({
dirs
:
[
'
components
'
],
rootDir
:
path
.
resolve
(
root
,
'
src
'
)
})
export
const
serverPluginEnv
:
ServerPlugin
=
({
root
,
watcher
})
=>
{
const
rootDir
=
path
.
resolve
(
root
,
'
src
'
)
const
dirs
=
[
'
components
'
].
map
(
dir
=>
path
.
resolve
(
rootDir
,
dir
))
const
easycomOptions
=
{
dirs
,
rootDir
:
rootDir
}
initEasycom
(
easycomOptions
)
watcher
.
on
(
'
all
'
,
(
eventName
,
path
)
=>
{
if
(
!
[
'
add
'
,
'
unlink
'
].
includes
(
eventName
))
{
return
}
if
(
dirs
.
find
(
dir
=>
path
.
startsWith
(
dir
)))
{
initEasycom
(
easycomOptions
)
}
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录