Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
良好的行为成为习惯
uni-app
提交
cb5c2d09
U
uni-app
项目概览
良好的行为成为习惯
/
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,发现更多精彩内容 >>
提交
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 {
...
@@ -70,8 +70,15 @@ class CollectDependency {
getJsonDeps
(
file
)
{
getJsonDeps
(
file
)
{
const
deps
=
[];
const
deps
=
[];
const
dirName
=
path
.
dirname
(
file
);
const
dirName
=
path
.
dirname
(
file
);
const
fileContent
=
this
.
readFileSync
(
file
);
let
fileContent
=
this
.
readFileSync
(
file
);
const
{
usingComponents
}
=
JSON
.
parse
(
fileContent
);
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
'
)
{
if
(
usingComponents
&&
typeof
usingComponents
===
'
object
'
)
{
Object
.
values
(
usingComponents
).
forEach
((
component
)
=>
{
Object
.
values
(
usingComponents
).
forEach
((
component
)
=>
{
component
=
resolveToContext
(
dirName
,
component
,
this
.
context
);
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 {
...
@@ -64,8 +64,8 @@ class Index extends Analyze {
let
cacheSet
=
new
Set
();
let
cacheSet
=
new
Set
();
let
cacheGlobalUsageMap
=
new
Map
();
let
cacheGlobalUsageMap
=
new
Map
();
// 收集包外组件
// 收集包外组件
const
colletOuterCompos
=
independentPage
=>
collectAllOutSideComponentsMap
(
independentRoot
,
emitFileMap
,
independentPage
,
cacheSet
,
cacheGlobalUsageMap
);
const
colle
c
tOuterCompos
=
independentPage
=>
collectAllOutSideComponentsMap
(
independentRoot
,
emitFileMap
,
independentPage
,
cacheSet
,
cacheGlobalUsageMap
);
independentPages
.
forEach
(
colletOuterCompos
);
independentPages
.
forEach
(
colle
c
tOuterCompos
);
// 如果是原生组件,则忽略wxComponents以外的组件
// 如果是原生组件,则忽略wxComponents以外的组件
cacheSet
=
[...
cacheSet
].
filter
(
componentPath
=>
{
cacheSet
=
[...
cacheSet
].
filter
(
componentPath
=>
{
...
@@ -162,6 +162,7 @@ class Index extends Analyze {
...
@@ -162,6 +162,7 @@ class Index extends Analyze {
// emitFileMap 后面会统一挂到assets上
// emitFileMap 后面会统一挂到assets上
if
(
!
fromAssetsFlag
)
return
;
if
(
!
fromAssetsFlag
)
return
;
delete
pageObj
.
usingGlobalComponents
compilationAssets
[
`
${
componentWhoUsedGlobalCompo
}
.json`
]
=
generateAsset
(
JSON
.
stringify
(
pageObj
));
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) {
...
@@ -14,7 +14,7 @@ function collectWxComponentUsedStatus (emitFileMap) {
}
}
const
explicitComponents
=
jsonFileInfo
.
usingComponents
||
{};
// 非全局组件
const
explicitComponents
=
jsonFileInfo
.
usingComponents
||
{};
// 非全局组件
const
usingGlobalWxComponents
=
jsonFileInfo
.
globalComponentsForOnDemand
||
{};
const
usingGlobalWxComponents
=
jsonFileInfo
.
usingGlobalComponents
||
{};
// FIX 全局组件和直接引用的组件名称相同的情况
// FIX 全局组件和直接引用的组件名称相同的情况
const
currentAllComponents
=
Object
.
assign
({},
usingGlobalWxComponents
,
explicitComponents
);
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
CopyOuterComponentsForIndependent
=
require
(
'
./copy-outer-components-for-independent
'
);
const
CopyWxComponentOnDemand
=
require
(
'
./copy-wx-components-on-demand
'
);
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
// @dcloudio/webpack-uni-mp-loader/lib/plugin/index-new.js
// 需要在在上述插件之后执行(获取处理过的json
// 需要在在上述插件之后执行(获取处理过的json
...
@@ -14,8 +11,6 @@ class DependencyAnalyze {
...
@@ -14,8 +11,6 @@ class DependencyAnalyze {
}
}
init
(
emitFileMap
,
compilation
)
{
init
(
emitFileMap
,
compilation
)
{
const
thisCompilationAssets
=
compilation
.
assets
;
const
manifestConfig
=
process
.
UNI_MANIFEST
;
const
manifestConfig
=
process
.
UNI_MANIFEST
;
const
weixinConfig
=
manifestConfig
[
'
mp-weixin
'
]
||
{};
const
weixinConfig
=
manifestConfig
[
'
mp-weixin
'
]
||
{};
const
independentSwitch
=
!!
weixinConfig
.
independentSwitch
;
const
independentSwitch
=
!!
weixinConfig
.
independentSwitch
;
...
@@ -28,8 +23,6 @@ class DependencyAnalyze {
...
@@ -28,8 +23,6 @@ class DependencyAnalyze {
if
(
independentSwitch
)
{
if
(
independentSwitch
)
{
new
CopyOuterComponentsForIndependent
(
emitFileMap
,
this
.
AnalyzeWxcomponentDependency
,
compilation
).
init
();
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) {
...
@@ -112,10 +112,11 @@ function normalizeUsingComponents (file, usingComponents) {
return
usingComponents
return
usingComponents
}
}
const
emit
FileMap
=
new
Map
();
const
cache
FileMap
=
new
Map
();
module
.
exports
=
function
generateJson
(
compilation
)
{
module
.
exports
=
function
generateJson
(
compilation
)
{
analyzeUsingComponents
()
analyzeUsingComponents
()
const
emitFileMap
=
new
Map
([...
cacheFileMap
]);
const
jsonFileMap
=
getChangedJsonFileMap
()
const
jsonFileMap
=
getChangedJsonFileMap
()
for
(
const
name
of
jsonFileMap
.
keys
())
{
for
(
const
name
of
jsonFileMap
.
keys
())
{
const
jsonObj
=
JSON
.
parse
(
jsonFileMap
.
get
(
name
))
const
jsonObj
=
JSON
.
parse
(
jsonFileMap
.
get
(
name
))
...
@@ -214,6 +215,7 @@ module.exports = function generateJson (compilation) {
...
@@ -214,6 +215,7 @@ module.exports = function generateJson (compilation) {
}
}
emitFileMap
.
set
(
name
,
jsonObj
);
emitFileMap
.
set
(
name
,
jsonObj
);
cacheFileMap
.
set
(
name
,
JSON
.
parse
(
JSON
.
stringify
(
jsonObj
)));
// 做一次拷贝,emitFileMap中内容在后面会被修改
}
}
...
@@ -221,8 +223,8 @@ module.exports = function generateJson (compilation) {
...
@@ -221,8 +223,8 @@ module.exports = function generateJson (compilation) {
(
new
AnalyzeDependency
()).
init
(
emitFileMap
,
compilation
);
(
new
AnalyzeDependency
()).
init
(
emitFileMap
,
compilation
);
for
(
const
[
name
,
jsonObj
]
of
emitFileMap
)
{
for
(
const
[
name
,
jsonObj
]
of
emitFileMap
)
{
emit
(
name
,
jsonObj
,
compilation
);
delete
jsonObj
.
usingGlobalComponents
;
delete
jsonObj
.
usingGlobalComponents
;
emit
(
name
,
jsonObj
,
compilation
);
}
}
if
(
process
.
env
.
UNI_USING_CACHE
&&
jsonFileMap
.
size
)
{
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录