Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
cb5c2d09
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
720
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,发现更多精彩内容 >>
提交
cb5c2d09
编写于
2月 23, 2022
作者:
S
songyu
提交者:
折腾笔记
4月 11, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 按需复制优化
上级
65049f2f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
17 addition
and
14 deletion
+17
-14
packages/uni-mp-weixin/lib/analyze-wxcomponent-dependency/collect-dependency.js
.../lib/analyze-wxcomponent-dependency/collect-dependency.js
+9
-2
packages/uni-mp-weixin/lib/independent-plugins/optimize-components-position/copy-outer-components-for-independent.js
...ponents-position/copy-outer-components-for-independent.js
+3
-2
packages/uni-mp-weixin/lib/independent-plugins/optimize-components-position/copy-wx-components-on-demand/collect-wx-component-used-status.js
...-components-on-demand/collect-wx-component-used-status.js
+1
-1
packages/uni-mp-weixin/lib/independent-plugins/optimize-components-position/index.js
...independent-plugins/optimize-components-position/index.js
+0
-7
packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
+4
-2
未找到文件。
packages/uni-mp-weixin/lib/analyze-wxcomponent-dependency/collect-dependency.js
浏览文件 @
cb5c2d09
...
...
@@ -70,8 +70,15 @@ class CollectDependency {
getJsonDeps
(
file
)
{
const
deps
=
[];
const
dirName
=
path
.
dirname
(
file
);
const
fileContent
=
this
.
readFileSync
(
file
);
const
{
usingComponents
}
=
JSON
.
parse
(
fileContent
);
let
fileContent
=
this
.
readFileSync
(
file
);
if
(
fileContent
&&
fileContent
instanceof
Buffer
)
{
fileContent
=
fileContent
.
toString
(
'
utf-8
'
);
}
if
(
!
fileContent
||
!
(
fileContent
.
trim
()))
{
return
[];
}
fileContent
=
JSON
.
parse
(
fileContent
);
const
usingComponents
=
fileContent
.
usingComponents
;
if
(
usingComponents
&&
typeof
usingComponents
===
'
object
'
)
{
Object
.
values
(
usingComponents
).
forEach
((
component
)
=>
{
component
=
resolveToContext
(
dirName
,
component
,
this
.
context
);
...
...
packages/uni-mp-weixin/lib/independent-plugins/optimize-components-position/copy-outer-components-for-independent.js
浏览文件 @
cb5c2d09
...
...
@@ -64,8 +64,8 @@ class Index extends Analyze {
let
cacheSet
=
new
Set
();
let
cacheGlobalUsageMap
=
new
Map
();
// 收集包外组件
const
colletOuterCompos
=
independentPage
=>
collectAllOutSideComponentsMap
(
independentRoot
,
emitFileMap
,
independentPage
,
cacheSet
,
cacheGlobalUsageMap
);
independentPages
.
forEach
(
colletOuterCompos
);
const
colle
c
tOuterCompos
=
independentPage
=>
collectAllOutSideComponentsMap
(
independentRoot
,
emitFileMap
,
independentPage
,
cacheSet
,
cacheGlobalUsageMap
);
independentPages
.
forEach
(
colle
c
tOuterCompos
);
// 如果是原生组件,则忽略wxComponents以外的组件
cacheSet
=
[...
cacheSet
].
filter
(
componentPath
=>
{
...
...
@@ -162,6 +162,7 @@ class Index extends Analyze {
// emitFileMap 后面会统一挂到assets上
if
(
!
fromAssetsFlag
)
return
;
delete
pageObj
.
usingGlobalComponents
compilationAssets
[
`
${
componentWhoUsedGlobalCompo
}
.json`
]
=
generateAsset
(
JSON
.
stringify
(
pageObj
));
});
}
...
...
packages/uni-mp-weixin/lib/independent-plugins/optimize-components-position/copy-wx-components-on-demand/collect-wx-component-used-status.js
浏览文件 @
cb5c2d09
...
...
@@ -14,7 +14,7 @@ function collectWxComponentUsedStatus (emitFileMap) {
}
const
explicitComponents
=
jsonFileInfo
.
usingComponents
||
{};
// 非全局组件
const
usingGlobalWxComponents
=
jsonFileInfo
.
globalComponentsForOnDemand
||
{};
const
usingGlobalWxComponents
=
jsonFileInfo
.
usingGlobalComponents
||
{};
// FIX 全局组件和直接引用的组件名称相同的情况
const
currentAllComponents
=
Object
.
assign
({},
usingGlobalWxComponents
,
explicitComponents
);
...
...
packages/uni-mp-weixin/lib/independent-plugins/optimize-components-position/index.js
浏览文件 @
cb5c2d09
const
CopyOuterComponentsForIndependent
=
require
(
'
./copy-outer-components-for-independent
'
);
const
CopyWxComponentOnDemand
=
require
(
'
./copy-wx-components-on-demand
'
);
const
{
getJsonFileMap
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/cache
'
);
const
{
generateAsset
}
=
require
(
'
./util
'
);
const
{
SyncBailHook
}
=
require
(
'
tapable
'
);
// @dcloudio/webpack-uni-mp-loader/lib/plugin/index-new.js
// 需要在在上述插件之后执行(获取处理过的json
...
...
@@ -14,8 +11,6 @@ class DependencyAnalyze {
}
init
(
emitFileMap
,
compilation
)
{
const
thisCompilationAssets
=
compilation
.
assets
;
const
manifestConfig
=
process
.
UNI_MANIFEST
;
const
weixinConfig
=
manifestConfig
[
'
mp-weixin
'
]
||
{};
const
independentSwitch
=
!!
weixinConfig
.
independentSwitch
;
...
...
@@ -28,8 +23,6 @@ class DependencyAnalyze {
if
(
independentSwitch
)
{
new
CopyOuterComponentsForIndependent
(
emitFileMap
,
this
.
AnalyzeWxcomponentDependency
,
compilation
).
init
();
}
// TODO 开关控制 按需复制wxcomponents
}
}
...
...
packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
浏览文件 @
cb5c2d09
...
...
@@ -112,10 +112,11 @@ function normalizeUsingComponents (file, usingComponents) {
return
usingComponents
}
const
emit
FileMap
=
new
Map
();
const
cache
FileMap
=
new
Map
();
module
.
exports
=
function
generateJson
(
compilation
)
{
analyzeUsingComponents
()
const
emitFileMap
=
new
Map
([...
cacheFileMap
]);
const
jsonFileMap
=
getChangedJsonFileMap
()
for
(
const
name
of
jsonFileMap
.
keys
())
{
const
jsonObj
=
JSON
.
parse
(
jsonFileMap
.
get
(
name
))
...
...
@@ -214,6 +215,7 @@ module.exports = function generateJson (compilation) {
}
emitFileMap
.
set
(
name
,
jsonObj
);
cacheFileMap
.
set
(
name
,
JSON
.
parse
(
JSON
.
stringify
(
jsonObj
)));
// 做一次拷贝,emitFileMap中内容在后面会被修改
}
...
...
@@ -221,8 +223,8 @@ module.exports = function generateJson (compilation) {
(
new
AnalyzeDependency
()).
init
(
emitFileMap
,
compilation
);
for
(
const
[
name
,
jsonObj
]
of
emitFileMap
)
{
emit
(
name
,
jsonObj
,
compilation
);
delete
jsonObj
.
usingGlobalComponents
;
emit
(
name
,
jsonObj
,
compilation
);
}
if
(
process
.
env
.
UNI_USING_CACHE
&&
jsonFileMap
.
size
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录