Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChenYFan_OHHH
uni-app
提交
120c69a2
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,发现更多精彩内容 >>
提交
120c69a2
编写于
5月 20, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: plugin
上级
30393129
变更
14
显示空白变更内容
内联
并排
Showing
14 changed file
with
128 addition
and
137 deletion
+128
-137
packages/uni-cli-shared/src/index.ts
packages/uni-cli-shared/src/index.ts
+0
-1
packages/uni-cli-shared/src/uni/compiler.ts
packages/uni-cli-shared/src/uni/compiler.ts
+0
-44
packages/uni-cli-shared/src/uni/index.ts
packages/uni-cli-shared/src/uni/index.ts
+0
-3
packages/uni-cli-shared/src/uni/plugin.ts
packages/uni-cli-shared/src/uni/plugin.ts
+0
-27
packages/uni-cloud/lib/uni.plugin.js
packages/uni-cloud/lib/uni.plugin.js
+42
-28
packages/uni-shared/dist/uni-shared.cjs.js
packages/uni-shared/dist/uni-shared.cjs.js
+2
-2
packages/uni-shared/dist/uni-shared.es.js
packages/uni-shared/dist/uni-shared.es.js
+2
-2
packages/uni-shared/src/dom/costomDataset.ts
packages/uni-shared/src/dom/costomDataset.ts
+3
-2
packages/vite-plugin-uni/src/config/index.ts
packages/vite-plugin-uni/src/config/index.ts
+1
-3
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
+1
-16
packages/vite-plugin-uni/src/configureServer/index.ts
packages/vite-plugin-uni/src/configureServer/index.ts
+0
-4
packages/vite-plugin-uni/src/index.ts
packages/vite-plugin-uni/src/index.ts
+9
-5
packages/vite-plugin-uni/src/utils/index.ts
packages/vite-plugin-uni/src/utils/index.ts
+1
-0
packages/vite-plugin-uni/src/utils/plugin.ts
packages/vite-plugin-uni/src/utils/plugin.ts
+67
-0
未找到文件。
packages/uni-cli-shared/src/index.ts
浏览文件 @
120c69a2
export
*
from
'
./ssr
'
export
*
from
'
./uni
'
export
*
from
'
./url
'
export
*
from
'
./deps
'
export
*
from
'
./json
'
...
...
packages/uni-cli-shared/src/uni/compiler.ts
已删除
100644 → 0
浏览文件 @
30393129
import
debug
from
'
debug
'
import
{
SyncHook
,
SyncWaterfallHook
}
from
'
tapable
'
import
{
UniPlugin
}
from
'
./plugin
'
interface
UniCompilerHooks
{
init
:
SyncHook
<
void
,
void
>
define
:
SyncWaterfallHook
<
Record
<
string
,
string
>>
inject
:
SyncWaterfallHook
<
Record
<
string
,
string
|
[
string
,
string
]
>>
done
:
SyncHook
<
void
,
void
>
}
const
debugCompiler
=
debug
(
'
uni:compiler
'
)
export
class
UniCompiler
{
hooks
:
UniCompilerHooks
constructor
({
plugins
}:
{
plugins
:
UniPlugin
[]
})
{
this
.
hooks
=
{
init
:
new
SyncHook
(),
define
:
new
SyncWaterfallHook
([
'
define
'
]),
inject
:
new
SyncWaterfallHook
([
'
inject
'
]),
done
:
new
SyncHook
(),
}
plugins
.
forEach
((
plugin
)
=>
{
debugCompiler
(
'
plugin
'
,
plugin
.
name
)
plugin
.
apply
(
this
)
})
}
init
()
{
return
this
.
hooks
.
init
.
call
()
}
define
()
{
const
define
=
this
.
hooks
.
define
.
call
({})
debugCompiler
(
'
define
'
,
define
)
return
define
}
inject
()
{
const
inject
=
this
.
hooks
.
inject
.
call
({})
debugCompiler
(
'
inject
'
,
inject
)
return
inject
}
done
()
{
return
this
.
hooks
.
done
.
call
()
}
}
packages/uni-cli-shared/src/uni/index.ts
已删除
100644 → 0
浏览文件 @
30393129
export
*
from
'
./utils
'
export
*
from
'
./compiler
'
export
*
from
'
./plugin
'
packages/uni-cli-shared/src/uni/plugin.ts
已删除
100644 → 0
浏览文件 @
30393129
import
{
isFunction
}
from
'
@vue/shared
'
import
{
UniCompiler
}
from
'
./compiler
'
export
interface
UniPluginConfig
{
init
?:
()
=>
void
define
?:
()
=>
Record
<
string
,
string
>
inject
?:
()
=>
Record
<
string
,
string
|
[
string
,
string
]
>
done
?:
()
=>
void
}
export
class
UniPlugin
{
name
:
string
private
options
:
UniPluginConfig
constructor
(
name
:
string
,
config
:
UniPluginConfig
=
{})
{
this
.
name
=
name
this
.
options
=
config
}
apply
(
compiler
:
UniCompiler
)
{
const
{
name
,
options
:
{
init
,
define
,
inject
,
done
},
}
=
this
isFunction
(
init
)
&&
compiler
.
hooks
.
init
.
tap
(
name
,
init
)
isFunction
(
define
)
&&
compiler
.
hooks
.
define
.
tap
(
name
,
define
)
isFunction
(
inject
)
&&
compiler
.
hooks
.
inject
.
tap
(
name
,
inject
)
isFunction
(
done
)
&&
compiler
.
hooks
.
done
.
tap
(
name
,
done
)
}
}
packages/uni-cloud/lib/uni.
config
.js
→
packages/uni-cloud/lib/uni.
plugin
.js
浏览文件 @
120c69a2
const
{
once
}
=
require
(
'
@dcloudio/uni-shared
'
)
module
.
exports
=
{
init
,
define
,
inject
,
done
:
once
(
done
),
const
{
uniInjectPlugin
}
=
require
(
'
@dcloudio/vite-plugin-uni
'
)
/**
* @type {import('vite').Plugin}
*/
const
UniCloudPlugin
=
{
name
:
'
vite:uni-cloud
'
,
config
()
{
initUniCloudEnv
()
return
{
define
:
{
'
process.env.UNI_CLOUD_PROVIDER
'
:
JSON
.
stringify
(
process
.
env
.
UNI_CLOUD_PROVIDER
),
'
process.env.UNICLOUD_DEBUG
'
:
JSON
.
stringify
(
process
.
env
.
UNICLOUD_DEBUG
),
},
}
},
configureServer
(
server
)
{
server
.
httpServer
&&
server
.
httpServer
.
on
(
'
listening
'
,
()
=>
{
if
(
!
process
.
UNI_CLOUD
)
{
return
}
process
.
nextTick
(()
=>
{
initUniCloudWarningOnce
()
})
})
},
}
function
init
()
{
const
initUniCloudWarningOnce
=
once
(()
=>
{
console
.
warn
(
'
当前项目使用了uniCloud,为避免云函数调用跨域问题,建议在HBuilderX内置浏览器里调试,如使用外部浏览器需处理跨域,详见:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5
'
)
})
function
initUniCloudEnv
()
{
process
.
UNI_CLOUD
=
false
process
.
UNI_CLOUD_TCB
=
false
process
.
UNI_CLOUD_ALIYUN
=
false
...
...
@@ -59,25 +89,9 @@ function init() {
}
}
function
define
()
{
return
{
'
process.env.UNI_CLOUD_PROVIDER
'
:
JSON
.
stringify
(
process
.
env
.
UNI_CLOUD_PROVIDER
),
'
process.env.UNICLOUD_DEBUG
'
:
JSON
.
stringify
(
process
.
env
.
UNICLOUD_DEBUG
),
}
}
function
inject
()
{
return
{
module
.
exports
=
[
UniCloudPlugin
,
uniInjectPlugin
({
uniCloud
:
[
'
@dcloudio/uni-cloud
'
,
'
default
'
],
}
}
function
done
()
{
if
(
process
.
UNI_CLOUD
)
{
console
.
warn
(
'
当前项目使用了uniCloud,为避免云函数调用跨域问题,建议在HBuilderX内置浏览器里调试,如使用外部浏览器需处理跨域,详见:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5
'
)
}
}
}),
]
packages/uni-shared/dist/uni-shared.cjs.js
浏览文件 @
120c69a2
...
...
@@ -12,8 +12,8 @@ function initCostomDataset() {
const
setAttribute
=
prototype
.
setAttribute
;
prototype
.
setAttribute
=
function
(
key
,
value
)
{
if
(
key
.
startsWith
(
'
data-
'
)
&&
this
.
tagName
.
startsWith
(
'
UNI-
'
))
{
const
dataset
=
(
this
.
__uniDataset
=
this
.
__uniDataset
||
{});
const
dataset
=
this
.
__uniDataset
||
(
this
.
__uniDataset
=
{});
dataset
[
formatKey
(
key
)]
=
value
;
}
setAttribute
.
call
(
this
,
key
,
value
);
...
...
packages/uni-shared/dist/uni-shared.es.js
浏览文件 @
120c69a2
...
...
@@ -8,8 +8,8 @@ function initCostomDataset() {
const
setAttribute
=
prototype
.
setAttribute
;
prototype
.
setAttribute
=
function
(
key
,
value
)
{
if
(
key
.
startsWith
(
'
data-
'
)
&&
this
.
tagName
.
startsWith
(
'
UNI-
'
))
{
const
dataset
=
(
this
.
__uniDataset
=
this
.
__uniDataset
||
{});
const
dataset
=
this
.
__uniDataset
||
(
this
.
__uniDataset
=
{});
dataset
[
formatKey
(
key
)]
=
value
;
}
setAttribute
.
call
(
this
,
key
,
value
);
...
...
packages/uni-shared/src/dom/costomDataset.ts
浏览文件 @
120c69a2
...
...
@@ -12,8 +12,9 @@ export function initCostomDataset() {
const
setAttribute
=
prototype
.
setAttribute
prototype
.
setAttribute
=
function
(
key
,
value
)
{
if
(
key
.
startsWith
(
'
data-
'
)
&&
this
.
tagName
.
startsWith
(
'
UNI-
'
))
{
const
dataset
=
((
this
as
HTMLElementWithDataset
).
__uniDataset
=
(
this
as
HTMLElementWithDataset
).
__uniDataset
||
{})
const
dataset
=
(
this
as
HTMLElementWithDataset
).
__uniDataset
||
((
this
as
HTMLElementWithDataset
).
__uniDataset
=
{})
dataset
[
formatKey
(
key
)]
=
value
}
setAttribute
.
call
(
this
,
key
,
value
)
...
...
packages/vite-plugin-uni/src/config/index.ts
浏览文件 @
120c69a2
import
path
from
'
path
'
import
{
extend
}
from
'
@vue/shared
'
import
{
Plugin
,
UserConfig
}
from
'
vite
'
import
{
normalizePath
,
parseManifestJsonOnce
}
from
'
@dcloudio/uni-cli-shared
'
...
...
@@ -44,14 +43,13 @@ export function createConfig(
options
.
vueOptions
=
initPluginVueOptions
(
options
)
options
.
vueJsxOptions
=
initPluginVueJsxOptions
(
options
)
options
.
viteLegacyOptions
=
initPluginViteLegacyOptions
(
options
)
options
.
compiler
.
init
()
const
define
=
createDefine
(
options
,
config
,
env
)
return
{
base
,
publicDir
:
config
.
publicDir
||
false
,
define
:
extend
(
define
,
options
.
compiler
.
define
())
,
define
,
resolve
:
createResolve
(
options
,
config
),
optimizeDeps
:
createOptimizeDeps
(
options
),
server
:
createServer
(
options
),
...
...
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
浏览文件 @
120c69a2
...
...
@@ -122,24 +122,9 @@ export function initPlugins(
addPlugin
(
plugins
,
uniPreVuePlugin
(),
'
vite:vue
'
,
'
pre
'
)
addPlugin
(
plugins
,
uniRenderjsPlugin
(),
'
vite:vue
'
)
const
injectOptions
=
options
.
compiler
.
inject
()
// 可以考虑使用apply:'build'
if
(
command
===
'
build
'
)
{
addPlugin
(
plugins
,
uniInjectPlugin
(
extend
(
uniInjectPluginOptions
,
injectOptions
)),
'
vite:vue
'
)
}
else
{
if
(
injectOptions
&&
Object
.
keys
(
injectOptions
).
length
)
{
addPlugin
(
plugins
,
uniInjectPlugin
(
extend
({
exclude
:
[...
COMMON_EXCLUDE
]
},
injectOptions
)
),
'
vite:vue
'
)
}
addPlugin
(
plugins
,
uniInjectPlugin
(
uniInjectPluginOptions
),
'
vite:vue
'
)
}
addPlugin
(
...
...
packages/vite-plugin-uni/src/configureServer/index.ts
浏览文件 @
120c69a2
...
...
@@ -9,10 +9,6 @@ export function createConfigureServer(
return
function
(
server
)
{
options
.
devServer
=
server
serveEasycom
(
server
,
options
)
server
.
httpServer
&&
server
.
httpServer
.
on
(
'
listening
'
,
()
=>
{
process
.
nextTick
(()
=>
options
.
compiler
.
done
())
})
return
()
=>
{
serveStatic
(
server
,
options
)
}
...
...
packages/vite-plugin-uni/src/index.ts
浏览文件 @
120c69a2
import
{
Plugin
,
ResolvedConfig
,
ViteDevServer
}
from
'
vite
'
import
{
UniCompiler
,
initUniCompiler
}
from
'
@dcloudio/uni-cli-shared
'
import
{
Options
as
VueOptions
}
from
'
@vitejs/plugin-vue
'
import
{
Options
as
ViteLegacyOptions
}
from
'
@vitejs/plugin-legacy
'
import
{
VueJSXPluginOptions
}
from
'
@vue/babel-plugin-jsx
'
...
...
@@ -10,6 +9,7 @@ import { createConfig } from './config'
import
{
createConfigResolved
}
from
'
./configResolved
'
import
{
createConfigureServer
}
from
'
./configureServer
'
import
{
createHandleHotUpdate
}
from
'
./handleHotUpdate
'
import
{
initExtraPlugins
}
from
'
./utils
'
export
interface
VitePluginUniOptions
{
inputDir
?:
string
outputDir
?:
string
...
...
@@ -25,7 +25,6 @@ export interface VitePluginUniResolvedOptions extends VitePluginUniOptions {
outputDir
:
string
assetsDir
:
string
devServer
?:
ViteDevServer
compiler
:
UniCompiler
}
export
*
from
'
./vue
'
...
...
@@ -51,9 +50,6 @@ export default function uniPlugin(
outputDir
:
''
,
command
:
'
serve
'
,
platform
:
'
h5
'
,
compiler
:
initUniCompiler
({
root
:
process
.
env
.
UNI_CLI_CONTEXT
||
process
.
cwd
(),
}),
}
const
plugins
:
Plugin
[]
=
[]
...
...
@@ -75,5 +71,13 @@ export default function uniPlugin(
configureServer
:
createConfigureServer
(
options
),
handleHotUpdate
:
createHandleHotUpdate
(
options
),
})
plugins
.
push
(
...
initExtraPlugins
(
process
.
env
.
UNI_CLI_CONTEXT
||
process
.
cwd
(),
(
process
.
env
.
UNI_PLATFORM
as
UniApp
.
PLATFORM
)
||
'
h5
'
)
)
return
plugins
}
export
{
uniInjectPlugin
}
from
'
./configResolved/plugins/inject
'
packages/vite-plugin-uni/src/utils/index.ts
浏览文件 @
120c69a2
export
*
from
'
./ast
'
export
*
from
'
./ssr
'
export
*
from
'
./filter
'
export
*
from
'
./plugin
'
export
*
from
'
./features
'
export
*
from
'
./easycom
'
export
*
from
'
./postcss
'
...
...
packages/
uni-cli-shared/src/uni/utils
.ts
→
packages/
vite-plugin-uni/src/utils/plugin
.ts
浏览文件 @
120c69a2
import
{
isArray
,
isString
}
from
'
@vue/shared
'
import
path
from
'
path
'
import
{
UniCompiler
}
from
'
./compiler
'
import
{
UniPlugin
}
from
'
./plugin
'
import
{
Plugin
}
from
'
vite
'
interface
PluginConfig
{
id
:
string
name
:
string
apply
?:
UniApp
.
PLATFORM
|
UniApp
.
PLATFORM
[]
config
:
{
name
:
string
main
?:
string
}
}
interface
InitUniCompilerOptions
{
r
oot
:
string
export
function
initExtraPlugins
(
cliRoot
:
string
,
platform
:
UniApp
.
PLATFORM
)
{
r
eturn
initPlugins
(
resolvePlugins
(
cliRoot
,
platform
))
}
export
function
initUniCompiler
(
opts
:
InitUniCompilerOptions
)
{
return
new
UniCompiler
({
plugins
:
initPlugins
(
resolvePlugins
(
opts
))
})
}
function
initPlugin
(
plugin
:
PluginConfig
)
{
function
initPlugin
(
plugin
:
PluginConfig
):
Plugin
|
void
{
const
configFile
=
path
.
join
(
plugin
.
id
,
plugin
.
config
.
main
||
'
/lib/uni.
config
.js
'
plugin
.
config
.
main
||
'
/lib/uni.
plugin
.js
'
)
try
{
/* eslint-disable no-restricted-globals */
return
new
UniPlugin
(
plugin
.
id
,
require
(
configFile
))
return
require
(
configFile
)
}
catch
(
e
)
{
console
.
warn
(
`
${
configFile
}
not found`
)
}
}
function
initPlugins
(
plugins
:
PluginConfig
[]):
Uni
Plugin
[]
{
function
initPlugins
(
plugins
:
PluginConfig
[]):
Plugin
[]
{
return
plugins
.
map
((
plugin
)
=>
initPlugin
(
plugin
))
.
filter
<
Uni
Plugin
>
(
Boolean
as
any
)
.
filter
<
Plugin
>
(
Boolean
as
any
)
}
function
resolvePlugins
(
opts
:
InitUniCompilerOptions
)
{
/* eslint-disable no-restricted-globals */
const
pkg
=
require
(
path
.
join
(
opts
.
root
,
'
package.json
'
))
function
resolvePlugins
(
cliRoot
:
string
,
platform
:
UniApp
.
PLATFORM
)
{
const
pkg
=
require
(
path
.
join
(
cliRoot
,
'
package.json
'
))
return
Object
.
keys
(
pkg
.
devDependencies
||
{})
.
concat
(
Object
.
keys
(
pkg
.
dependencies
||
{}))
.
map
((
id
)
=>
{
.
map
<
PluginConfig
|
void
>
((
id
)
=>
{
try
{
/* eslint-disable no-restricted-globals */
const
pluginPkg
=
require
(
id
+
'
/package.json
'
)
const
config
=
pluginPkg
[
'
uni-app
'
]
const
config
=
pluginPkg
[
'
uni-app
'
]
as
PluginConfig
if
(
!
config
||
!
config
.
name
)
{
return
}
const
{
apply
}
=
config
if
(
isArray
(
apply
))
{
if
(
!
apply
.
includes
(
platform
))
{
return
}
}
else
if
(
isString
(
apply
))
{
if
(
apply
!==
platform
)
{
return
}
}
return
{
id
,
name
:
config
.
name
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录