Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
ca339c01
U
uni-app
项目概览
DCloud
/
uni-app
2 个月 前同步成功
通知
715
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,发现更多精彩内容 >>
提交
ca339c01
编写于
4月 07, 2022
作者:
S
songyu
提交者:
折腾笔记
4月 11, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 修复globalThis问题, 删除无效代码, 删除app.json中的无效属性
上级
cb5c2d09
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
43 addition
and
48 deletion
+43
-48
packages/uni-mp-weixin/lib/analyze-wxcomponent-dependency/collect-dependency.js
.../lib/analyze-wxcomponent-dependency/collect-dependency.js
+2
-2
packages/uni-mp-weixin/lib/independent-plugins/app-interceptor-plugin.js
...-weixin/lib/independent-plugins/app-interceptor-plugin.js
+3
-2
packages/uni-mp-weixin/lib/independent-plugins/inject-main-css-to-independent-plugin.js
...ependent-plugins/inject-main-css-to-independent-plugin.js
+19
-13
packages/uni-mp-weixin/lib/independent-plugins/insert-weui-css-to-independent-plugin.js
...ependent-plugins/insert-weui-css-to-independent-plugin.js
+0
-20
packages/uni-mp-weixin/lib/independent-plugins/optimize-components-position/constant.js
...ependent-plugins/optimize-components-position/constant.js
+1
-1
packages/uni-mp-weixin/lib/independent-plugins/optimize-components-position/copy-outer-components-for-independent.js
...ponents-position/copy-outer-components-for-independent.js
+1
-1
packages/uni-mp-weixin/lib/runtime/wxMpRuntime.js
packages/uni-mp-weixin/lib/runtime/wxMpRuntime.js
+5
-3
packages/webpack-uni-mp-loader/lib/plugin/generate-component.js
...es/webpack-uni-mp-loader/lib/plugin/generate-component.js
+2
-2
packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
+10
-4
未找到文件。
packages/uni-mp-weixin/lib/analyze-wxcomponent-dependency/collect-dependency.js
浏览文件 @
ca339c01
...
...
@@ -72,10 +72,10 @@ class CollectDependency {
const
dirName
=
path
.
dirname
(
file
);
let
fileContent
=
this
.
readFileSync
(
file
);
if
(
fileContent
&&
fileContent
instanceof
Buffer
)
{
fileContent
=
fileContent
.
toString
(
'
utf-8
'
);
fileContent
=
fileContent
.
toString
(
'
utf-8
'
);
}
if
(
!
fileContent
||
!
(
fileContent
.
trim
()))
{
return
[];
return
[];
}
fileContent
=
JSON
.
parse
(
fileContent
);
const
usingComponents
=
fileContent
.
usingComponents
;
...
...
packages/uni-mp-weixin/lib/independent-plugins/app-interceptor-plugin.js
浏览文件 @
ca339c01
...
...
@@ -13,10 +13,11 @@ const visitor = {
// 增减判断是否有该参数逻辑
if
(
t
.
isIdentifier
(
path
.
node
.
callee
))
{
const
logicGlobal
=
'
(Function("return this")())
'
if
(
funNode
.
callee
.
name
===
'
getApp
'
&&
funNode
.
arguments
.
length
===
0
)
{
funNode
.
callee
=
t
.
MemberExpression
(
t
.
Identifier
(
'
(global.global || global)
'
),
t
.
Identifier
(
'
getApp
'
));
funNode
.
callee
=
t
.
MemberExpression
(
t
.
Identifier
(
logicGlobal
),
t
.
Identifier
(
'
getApp
'
));
}
else
if
(
funNode
.
callee
.
name
===
'
App
'
)
{
funNode
.
callee
=
t
.
MemberExpression
(
t
.
Identifier
(
'
(global.global || global)
'
),
t
.
Identifier
(
'
App
'
));
funNode
.
callee
=
t
.
MemberExpression
(
t
.
Identifier
(
logicGlobal
),
t
.
Identifier
(
'
App
'
));
}
}
},
...
...
packages/uni-mp-weixin/lib/independent-plugins/inject-main-css-to-independent-plugin.js
浏览文件 @
ca339c01
const
fs
=
require
(
'
fs-extra
'
);
const
path
=
require
(
'
path
'
);
const
{
generateAsset
}
=
require
(
'
./utils
'
);
const
{
getNewComponentPathInIndependentPkg
,
getJsonByPageOrComponentPath
}
=
require
(
'
./optimize-components-position/util
'
);
const
{
getIndependentPkgRoots
,
getIndependentEntryPages
}
=
require
(
'
@dcloudio/uni-mp-weixin/lib/independent-plugins/optimize-components-position/util
'
);
const
{
wxComponentsStr
}
=
require
(
'
./optimize-components-position/constant
'
);
const
weuiMiniprogramDir
=
'
weui-mp
'
;
function
generateCssSource
(
pkgMainCssPath
,
pkgLibraryCssPath
,
wxssSourceInfo
)
{
const
platforms
=
[
'
mp-weixin
'
,
'
mp-qq
'
,
'
mp-toutiao
'
];
const
presetStyle
=
platforms
.
includes
(
process
.
env
.
UNI_PLATFORM
)
?
'
[data-custom-hidden="true"],[bind-data-custom-hidden="true"]{display: none !important;}
'
:
''
;
return
`@import '/
${
pkgMainCssPath
}
';
@import '/
${
pkgLibraryCssPath
}
';
const
mainCssImport
=
pkgMainCssPath
?
`@import '/
${
pkgMainCssPath
}
';`
:
''
;
const
libraryCssImport
=
pkgLibraryCssPath
?
`@import '/
${
pkgLibraryCssPath
}
';`
:
''
;
return
`
${
mainCssImport
}${
libraryCssImport
}
${
wxssSourceInfo
.
source
()}
${
presetStyle
}
`
;
}
function
copyWeuiCssToIndependent
(
independentRoot
)
{
const
weuiCssRelativePath
=
'
wxcomponents/weui-miniprogram/weui-wxss/dist/style/weui.wxss
'
;
const
weuiCssRelativePath
=
`wxcomponents/
${
weuiMiniprogramDir
}
/weui-wxss/dist/style/weui.wxss`
;
const
fromPath
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
weuiCssRelativePath
);
const
toPath
=
path
.
resolve
(
process
.
env
.
UNI_OUTPUT_DIR
,
`
${
independentRoot
}
/
${
weuiCssRelativePath
}
`
);
if
(
fs
.
existsSync
(
fromPath
))
{
...
...
@@ -43,7 +42,7 @@ function tryInsertWeuiCss (independentRoot, originalWxssStr) {
// 复制
const
successOrNot
=
copyWeuiCssToIndependent
(
independentRoot
);
const
insertStr
=
`@import '/
${
independentRoot
}
/wxcomponents/
weui-miniprogram
/weui-wxss/dist/style/weui.wxss'`
;
const
insertStr
=
`@import '/
${
independentRoot
}
/wxcomponents/
${
weuiMiniprogramDir
}
/weui-wxss/dist/style/weui.wxss'`
;
return
(
successOrNot
&&
useExtendedWeUi
)
?
`
${
insertStr
}
;
${
originalWxssStr
}
`
:
originalWxssStr
;
}
...
...
@@ -54,14 +53,21 @@ class InjectMainCssToIndependentCssPlugin {
compiler
.
hooks
.
emit
.
tapPromise
(
'
InjectMainCssToIndependentCssPlugin
'
,
compilation
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
// TODO 判断主包中 common/main.wxss是否存在,不存在直接return
const
thisCompilationAssets
=
compilation
.
assets
;
const
indendentRoots
=
getIndependentPkgRoots
();
indendentRoots
.
forEach
(
indendentRoot
=>
{
const
pkgMainCssPath
=
`
${
indendentRoot
}
/common/main.wxss`
;
const
pkgLibraryCssPath
=
`
${
indendentRoot
}
/common/library.wxss`
;
let
pkgMainCssPath
=
`
${
indendentRoot
}
/common/main.wxss`
;
let
pkgLibraryCssPath
=
`
${
indendentRoot
}
/common/library.wxss`
;
if
(
!
thisCompilationAssets
[
pkgMainCssPath
]){
pkgMainCssPath
=
''
;
}
if
(
!
thisCompilationAssets
[
pkgLibraryCssPath
]){
pkgLibraryCssPath
=
''
;
}
const
pkgPagesPath
=
getIndependentEntryPages
(
indendentRoot
);
// const cacheSet = new Set();
...
...
@@ -77,7 +83,7 @@ class InjectMainCssToIndependentCssPlugin {
pageAndComponentPath
=
pageAndComponentPath
.
substring
(
1
);
}
if
(
pageAndComponentPath
.
indexOf
(
'
weui-miniprogra
'
)
>=
0
)
{
if
(
pageAndComponentPath
.
indexOf
(
wxComponentsStr
)
>=
0
)
{
return
;
}
const
pageWxssPath
=
`
${
pageAndComponentPath
}
.wxss`
;
...
...
packages/uni-mp-weixin/lib/independent-plugins/insert-weui-css-to-independent-plugin.js
已删除
100644 → 0
浏览文件 @
cb5c2d09
@
import
'
weui-miniprogram/weui-wxss/dist/style/weui.wxss
'
;
class
InjectWeuiCssToIndependentPlugin
{
apply
(
compiler
)
{
compiler
.
hooks
.
emit
.
tapPromise
(
'
InjectWeuiCssToIndependentPlugin
'
,
compilation
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
const
thisCompilationAssets
=
compilation
.
assets
;
resolve
();
}
catch
(
e
)
{
console
.
error
(
'
independent.error
'
,
'
InjectWeuiCssToIndependentPlugin
'
,
e
);
reject
(
e
);
}
});
});
}
}
module
.
exports
=
InjectMainCssToIndepe
;
\ No newline at end of file
packages/uni-mp-weixin/lib/independent-plugins/optimize-components-position/constant.js
浏览文件 @
ca339c01
module
.
exports
=
{
appJsonFileName
:
'
app.json
'
,
wxComponentsStr
:
'
wxcomponents
'
,
weuiComponentStr
:
'
weui-miniprogram
'
+
'
dd
'
,
weuiComponentStr
:
'
weui-miniprogram
'
,
mainPkgName
:
'
mainPkg
'
,
outerComponents
:
'
vueOuterComponents
'
,
componentType
:
{
...
...
packages/uni-mp-weixin/lib/independent-plugins/optimize-components-position/copy-outer-components-for-independent.js
浏览文件 @
ca339c01
...
...
@@ -118,7 +118,7 @@ class Index extends Analyze {
addGlobalComponentReference
(
independentRoot
,
globalComponentsMap
)
{
const
globalComponentInfoMap
=
getGlobalComponentKeyByGlobalComponentPath
();
for
(
let
[
globalComponentPath
,
componentSetWhoUsedGlobalCompo
]
of
globalComponentsMap
)
{
// weui暂时先不处理
// weui
暂时先不处理
if
(
globalComponentPath
.
indexOf
(
weuiComponentStr
)
>=
0
)
{
continue
;
}
...
...
packages/uni-mp-weixin/lib/runtime/wxMpRuntime.js
浏览文件 @
ca339c01
if
(
!
global
.
wpRuntimeInited
)
{
global
.
wpRuntimeInited
=
true
;
const
logicGlobal
=
Function
(
"
return this
"
)();
if
(
!
logicGlobal
.
wpRuntimeInited
)
{
logicGlobal
.
wpRuntimeInited
=
true
;
// https://developers.weixin.qq.com/miniprogram/dev/reference/api/App.html
// 注册小程序。接受一个 Object 参数,其指定小程序的生命周期回调等。
// App() 必须在 app.js 中调用,必须调用且只能调用一次。不然会出现无法预期的后果。
const
independentRoots
=
[];
// 变量名不能更改,插件通过该名来静态替换值
Object
.
assign
(
g
lobal
,
{
Object
.
assign
(
logicG
lobal
,
{
getApp
:
function
()
{
return
getApp
()
||
getApp
({
allowDefault
:
true
});
},
...
...
packages/webpack-uni-mp-loader/lib/plugin/generate-component.js
浏览文件 @
ca339c01
...
...
@@ -315,7 +315,7 @@ function addComponent (name) {
function
removeUnusedComponent
(
name
)
{
try
{
//
fs.renameSync(path.join(process.env.UNI_OUTPUT_DIR, name + '.json'), path.join(process.env.UNI_OUTPUT_DIR, name +
//
'.bak.json'))
fs
.
renameSync
(
path
.
join
(
process
.
env
.
UNI_OUTPUT_DIR
,
name
+
'
.json
'
),
path
.
join
(
process
.
env
.
UNI_OUTPUT_DIR
,
name
+
'
.bak.json
'
))
}
catch
(
e
)
{
}
}
packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
浏览文件 @
ca339c01
...
...
@@ -222,10 +222,16 @@ module.exports = function generateJson (compilation) {
// 组件依赖分析
(
new
AnalyzeDependency
()).
init
(
emitFileMap
,
compilation
);
for
(
const
[
name
,
jsonObj
]
of
emitFileMap
)
{
delete
jsonObj
.
usingGlobalComponents
;
emit
(
name
,
jsonObj
,
compilation
);
}
for
(
const
[
name
,
jsonObj
]
of
emitFileMap
)
{
if
(
name
===
'
app.json
'
)
{
// 删除manifest.json携带的配置项
delete
jsonObj
.
insertAppCssToIndependentSwitch
;
delete
jsonObj
.
independentSwitch
;
delete
jsonObj
.
copyWxComponentsOnDemandSwitch
;
}
else
{
// 删除用于临时记录的属性
delete
jsonObj
.
usingGlobalComponents
;
}
emit
(
name
,
jsonObj
,
compilation
);
}
if
(
process
.
env
.
UNI_USING_CACHE
&&
jsonFileMap
.
size
)
{
setTimeout
(()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录