Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
d6e1c8ef
U
uni-app
项目概览
DCloud
/
uni-app
大约 1 个月 前同步成功
通知
702
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d6e1c8ef
编写于
6月 10, 2020
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(v3): subPackages
上级
aecbbd7c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
162 addition
and
120 deletion
+162
-120
packages/uni-app-plus/dist/index.v3.js
packages/uni-app-plus/dist/index.v3.js
+109
-91
packages/webpack-uni-pages-loader/lib/platforms/app-plus/app-config-service.js
...pages-loader/lib/platforms/app-plus/app-config-service.js
+4
-2
src/platforms/app-plus/service/api/plugin/load-sub-package.js
...platforms/app-plus/service/api/plugin/load-sub-package.js
+20
-2
src/platforms/app-plus/service/api/plugin/restore-global.js
src/platforms/app-plus/service/api/plugin/restore-global.js
+4
-3
src/platforms/app-plus/service/framework/load-sub-package.js
src/platforms/app-plus/service/framework/load-sub-package.js
+25
-22
未找到文件。
packages/uni-app-plus/dist/index.v3.js
浏览文件 @
d6e1c8ef
...
...
@@ -7414,7 +7414,7 @@ var serviceContext = (function () {
console
.
log
(
`[restoreGlobal][
${
Date
.
now
()}
]`
);
}
weex
=
newWeex
;
plus
=
newPlus
;
plus
=
newPlus
;
plus
.
navigator
.
setStatusBarStyle
=
newSetStatusBarStyle
;
/* eslint-disable no-global-assign */
setTimeout
=
newSetTimeout
;
...
...
@@ -7422,6 +7422,7 @@ var serviceContext = (function () {
setInterval
=
newSetInterval
;
clearInterval
=
newClearInterval
;
}
__uniConfig
.
serviceReady
=
true
;
}
function
wrapper$1
(
webview
)
{
...
...
@@ -7523,17 +7524,119 @@ var serviceContext = (function () {
return
weex
.
requireModule
(
'
plus
'
).
sendNativeEvent
(
event
,
data
,
callback
)
}
const
loadedSubPackages
=
[];
/**
* 指定路由 ready 后,检查是否触发分包预加载
* @param {Object} route
*/
function
preloadSubPackages
(
route
)
{
if
(
!
__uniConfig
.
preloadRule
)
{
return
}
const
options
=
__uniConfig
.
preloadRule
[
route
];
if
(
!
options
||
!
Array
.
isArray
(
options
.
packages
))
{
return
}
const
packages
=
options
.
packages
.
filter
(
root
=>
loadedSubPackages
.
indexOf
(
root
)
===
-
1
);
if
(
!
packages
.
length
)
{
return
}
loadSubPackages
(
options
.
packages
);
// 暂不需要网络下载
// const network = options.network || 'wifi'
// if (network === 'wifi') {
// uni.getNetworkType({
// success (res) {
// if (process.env.NODE_ENV !== 'production') {
// console.log('UNIAPP[preloadRule]:' + res.networkType + ':' + JSON.stringify(options))
// }
// if (res.networkType === 'wifi') {
// loadSubPackages(options.packages)
// }
// }
// })
// } else {
// if (process.env.NODE_ENV !== 'production') {
// console.log('UNIAPP[preloadRule]:' + JSON.stringify(options))
// }
// loadSubPackages(options.packages)
// }
}
function
loadPage
(
route
,
callback
)
{
let
isInSubPackage
=
false
;
const
subPackages
=
__uniConfig
.
subPackages
;
if
(
Array
.
isArray
(
subPackages
))
{
const
subPackage
=
subPackages
.
find
(
subPackage
=>
route
.
indexOf
(
subPackage
.
root
)
===
0
);
if
(
subPackage
)
{
isInSubPackage
=
true
;
loadSubPackage$1
(
subPackage
.
root
,
callback
);
}
}
if
(
!
isInSubPackage
)
{
callback
();
}
}
function
loadSubPackage$1
(
root
,
callback
)
{
if
(
loadedSubPackages
.
indexOf
(
root
)
!==
-
1
)
{
return
callback
()
}
loadSubPackages
([
root
],
()
=>
{
callback
();
});
}
const
SUB_FILENAME
=
'
app-sub-service.js
'
;
function
evaluateScriptFiles
(
files
,
callback
)
{
__uniConfig
.
onServiceReady
(()
=>
{
weex
.
requireModule
(
'
plus
'
).
evalJSFiles
(
files
,
callback
);
});
}
function
loadSubPackages
(
packages
,
callback
)
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
UNIAPP[loadSubPackages]:
'
+
JSON
.
stringify
(
packages
));
}
const
startTime
=
Date
.
now
();
evaluateScriptFiles
(
packages
.
map
(
root
=>
{
loadedSubPackages
.
push
(
root
);
return
root
+
'
/
'
+
SUB_FILENAME
}),
res
=>
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
UNIAPP[loadSubPackages]:耗时(
'
+
(
Date
.
now
()
-
startTime
)
+
'
)
'
);
}
callback
&&
callback
(
true
);
});
}
const
SUB_FILENAME$1
=
'
app-sub-service.js
'
;
function
evaluateScriptFile
(
file
,
callback
)
{
// TODO 有可能当前 instance 是非 app-service
weex
.
requireModule
(
'
plus
'
).
evalJSFiles
([
file
],
callback
);
__uniConfig
.
onServiceReady
(()
=>
{
weex
.
requireModule
(
'
plus
'
).
evalJSFiles
([
file
],
callback
);
});
}
function
loadSubPackage$
1
({
function
loadSubPackage$
2
({
root
},
callbackId
)
{
evaluateScriptFile
(
root
+
'
/
'
+
SUB_FILENAME
,
res
=>
{
if
(
loadedSubPackages
.
indexOf
(
root
)
!==
-
1
)
{
return
{
errMsg
:
'
loadSubPackage:ok
'
}
}
loadedSubPackages
.
push
(
root
);
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
UNIAPP[loadSubPackage]:
'
+
root
);
}
const
startTime
=
Date
.
now
();
evaluateScriptFile
(
root
+
'
/
'
+
SUB_FILENAME$1
,
res
=>
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
UNIAPP[loadSubPackage]:耗时(
'
+
(
Date
.
now
()
-
startTime
)
+
'
)
'
);
}
invoke$1
(
callbackId
,
{
errMsg
:
'
loadSubPackage:ok
'
});
...
...
@@ -8430,91 +8533,6 @@ var serviceContext = (function () {
return
pageVm
}
const
loadedSubPackages
=
[];
/**
* 指定路由 ready 后,检查是否触发分包预加载
* @param {Object} route
*/
function
preloadSubPackages
(
route
)
{
if
(
!
__uniConfig
.
preloadRule
)
{
return
}
const
options
=
__uniConfig
.
preloadRule
[
route
];
if
(
!
options
||
!
Array
.
isArray
(
options
.
packages
))
{
return
}
const
packages
=
options
.
packages
.
filter
(
root
=>
loadedSubPackages
.
indexOf
(
root
)
===
-
1
);
if
(
!
packages
.
length
)
{
return
}
const
network
=
options
.
network
||
'
wifi
'
;
if
(
network
===
'
wifi
'
)
{
uni
.
getNetworkType
({
success
(
res
)
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
UNIAPP[preloadRule]:
'
+
res
.
networkType
+
'
:
'
+
JSON
.
stringify
(
options
));
}
if
(
res
.
networkType
===
'
wifi
'
)
{
loadSubPackages
(
options
.
packages
);
}
}
});
}
else
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
UNIAPP[preloadRule]:
'
+
JSON
.
stringify
(
options
));
}
loadSubPackages
(
options
.
packages
);
}
}
function
loadPage
(
route
,
callback
)
{
let
isInSubPackage
=
false
;
const
subPackages
=
__uniConfig
.
subPackages
;
if
(
Array
.
isArray
(
subPackages
))
{
const
subPackage
=
subPackages
.
find
(
subPackage
=>
route
.
indexOf
(
subPackage
.
root
)
===
0
);
if
(
subPackage
)
{
isInSubPackage
=
true
;
loadSubPackage$2
(
subPackage
.
root
,
callback
);
}
}
if
(
!
isInSubPackage
)
{
callback
();
}
}
function
loadSubPackage$2
(
root
,
callback
)
{
if
(
loadedSubPackages
.
indexOf
(
root
)
!==
-
1
)
{
return
callback
()
}
loadSubPackages
([
root
],
()
=>
{
callback
();
});
}
const
SUB_FILENAME$1
=
'
app-sub-service.js
'
;
function
evaluateScriptFiles
(
files
,
callback
)
{
// TODO 有可能当前 instance 是非 app-service
weex
.
requireModule
(
'
plus
'
).
evalJSFiles
(
files
,
callback
);
}
function
loadSubPackages
(
packages
,
callback
)
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
UNIAPP[loadSubPackages]:
'
+
JSON
.
stringify
(
packages
));
}
const
startTime
=
Date
.
now
();
evaluateScriptFiles
(
packages
.
map
(
root
=>
{
loadedSubPackages
.
push
(
root
);
return
root
+
'
/
'
+
SUB_FILENAME$1
}),
res
=>
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
UNIAPP[loadSubPackages]:
'
+
(
Date
.
now
()
-
startTime
));
}
callback
&&
callback
(
true
);
});
}
const
pages
=
[];
function
getCurrentPages$1
(
returnAll
)
{
...
...
@@ -9933,7 +9951,7 @@ var serviceContext = (function () {
getCurrentSubNVue
:
getCurrentSubNVue
,
onNativeEventReceive
:
onNativeEventReceive
,
sendNativeEvent
:
sendNativeEvent
,
loadSubPackage
:
loadSubPackage$
1
,
loadSubPackage
:
loadSubPackage$
2
,
navigateBack
:
navigateBack$1
,
navigateTo
:
navigateTo$1
,
reLaunch
:
reLaunch$1
,
...
...
packages/webpack-uni-pages-loader/lib/platforms/app-plus/app-config-service.js
浏览文件 @
d6e1c8ef
...
...
@@ -67,10 +67,12 @@ module.exports = function definePages (appJson) {
return
{
name
:
'
app-config-service.js
'
,
content
:
`
var isReady=false;var onReadyCallbacks=[];
var isReady=false;var onReadyCallbacks=[];
var isServiceReady=false;var onServiceReadyCallbacks=[];
var __uniConfig =
${
JSON
.
stringify
(
appJson
,
null
)}
;
var __uniRoutes =
${
JSON
.
stringify
(
__uniRoutes
)}
;
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
__uniConfig.onServiceReady=function(callback){if(__uniConfig.serviceReady){callback()}else{onServiceReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"serviceReady",{get:function(){return isServiceReady},set:function(val){isServiceReady=val;if(!isServiceReady){return}const callbacks=onServiceReadyCallbacks.slice(0);onServiceReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
service.register("uni-app-config",{create(a,b,c){if(!__uniConfig.viewport){var d=b.weex.config.env.scale,e=b.weex.config.env.deviceWidth,f=Math.ceil(e/d);Object.assign(__uniConfig,{viewport:f,defaultFontSize:Math.round(f/20)})}return{instance:{__uniConfig:__uniConfig,__uniRoutes:__uniRoutes,
${
globalStatement
}
}}}});
`
}
...
...
src/platforms/app-plus/service/api/plugin/load-sub-package.js
浏览文件 @
d6e1c8ef
...
...
@@ -2,17 +2,35 @@ import {
invoke
}
from
'
../../bridge
'
import
{
loadedSubPackages
}
from
'
../../framework/load-sub-package
'
const
SUB_FILENAME
=
'
app-sub-service.js
'
function
evaluateScriptFile
(
file
,
callback
)
{
// TODO 有可能当前 instance 是非 app-service
weex
.
requireModule
(
'
plus
'
).
evalJSFiles
([
file
],
callback
)
__uniConfig
.
onServiceReady
(()
=>
{
weex
.
requireModule
(
'
plus
'
).
evalJSFiles
([
file
],
callback
)
})
}
export
function
loadSubPackage
({
root
},
callbackId
)
{
if
(
loadedSubPackages
.
indexOf
(
root
)
!==
-
1
)
{
return
{
errMsg
:
'
loadSubPackage:ok
'
}
}
loadedSubPackages
.
push
(
root
)
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
UNIAPP[loadSubPackage]:
'
+
root
)
}
const
startTime
=
Date
.
now
()
evaluateScriptFile
(
root
+
'
/
'
+
SUB_FILENAME
,
res
=>
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
UNIAPP[loadSubPackage]:耗时(
'
+
(
Date
.
now
()
-
startTime
)
+
'
)
'
)
}
invoke
(
callbackId
,
{
errMsg
:
'
loadSubPackage:ok
'
})
...
...
src/platforms/app-plus/service/api/plugin/restore-global.js
浏览文件 @
d6e1c8ef
import
{
newSetStatusBarStyle
}
from
'
../../bridge
'
}
from
'
../../bridge
'
export
function
restoreGlobal
(
newWeex
,
newPlus
,
...
...
@@ -19,7 +19,7 @@ export function restoreGlobal (
console
.
log
(
`[restoreGlobal][
${
Date
.
now
()}
]`
)
}
weex
=
newWeex
plus
=
newPlus
plus
=
newPlus
plus
.
navigator
.
setStatusBarStyle
=
newSetStatusBarStyle
/* eslint-disable no-global-assign */
setTimeout
=
newSetTimeout
...
...
@@ -27,4 +27,5 @@ export function restoreGlobal (
setInterval
=
newSetInterval
clearInterval
=
newClearInterval
}
__uniConfig
.
serviceReady
=
true
}
src/platforms/app-plus/service/framework/load-sub-package.js
浏览文件 @
d6e1c8ef
const
loadedSubPackages
=
[]
export
const
loadedSubPackages
=
[]
/**
* 指定路由 ready 后,检查是否触发分包预加载
...
...
@@ -16,24 +16,26 @@ export function preloadSubPackages (route) {
if
(
!
packages
.
length
)
{
return
}
const
network
=
options
.
network
||
'
wifi
'
if
(
network
===
'
wifi
'
)
{
uni
.
getNetworkType
({
success
(
res
)
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
UNIAPP[preloadRule]:
'
+
res
.
networkType
+
'
:
'
+
JSON
.
stringify
(
options
))
}
if
(
res
.
networkType
===
'
wifi
'
)
{
loadSubPackages
(
options
.
packages
)
}
}
})
}
else
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
UNIAPP[preloadRule]:
'
+
JSON
.
stringify
(
options
))
}
loadSubPackages
(
options
.
packages
)
}
loadSubPackages
(
options
.
packages
)
// 暂不需要网络下载
// const network = options.network || 'wifi'
// if (network === 'wifi') {
// uni.getNetworkType({
// success (res) {
// if (process.env.NODE_ENV !== 'production') {
// console.log('UNIAPP[preloadRule]:' + res.networkType + ':' + JSON.stringify(options))
// }
// if (res.networkType === 'wifi') {
// loadSubPackages(options.packages)
// }
// }
// })
// } else {
// if (process.env.NODE_ENV !== 'production') {
// console.log('UNIAPP[preloadRule]:' + JSON.stringify(options))
// }
// loadSubPackages(options.packages)
// }
}
export
function
loadPage
(
route
,
callback
)
{
...
...
@@ -63,8 +65,9 @@ function loadSubPackage (root, callback) {
const
SUB_FILENAME
=
'
app-sub-service.js
'
function
evaluateScriptFiles
(
files
,
callback
)
{
// TODO 有可能当前 instance 是非 app-service
weex
.
requireModule
(
'
plus
'
).
evalJSFiles
(
files
,
callback
)
__uniConfig
.
onServiceReady
(()
=>
{
weex
.
requireModule
(
'
plus
'
).
evalJSFiles
(
files
,
callback
)
})
}
function
loadSubPackages
(
packages
,
callback
)
{
...
...
@@ -77,7 +80,7 @@ function loadSubPackages (packages, callback) {
return
root
+
'
/
'
+
SUB_FILENAME
}),
res
=>
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
UNIAPP[loadSubPackages]:
'
+
(
Date
.
now
()
-
startTime
)
)
console
.
log
(
'
UNIAPP[loadSubPackages]:
耗时(
'
+
(
Date
.
now
()
-
startTime
)
+
'
)
'
)
}
callback
&&
callback
(
true
)
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录