Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
83c597e9
U
uni-app
项目概览
DCloud
/
uni-app
28 天 前同步成功
通知
702
Star
38704
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,发现更多精彩内容 >>
提交
83c597e9
编写于
8月 09, 2022
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: updateAsset with webpack5
上级
f11e7d60
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
59 addition
and
16 deletion
+59
-16
packages/webpack-uni-mp-loader/lib/plugin/generate-component.js
...es/webpack-uni-mp-loader/lib/plugin/generate-component.js
+57
-15
packages/webpack-uni-mp-loader/lib/plugin/index-new.js
packages/webpack-uni-mp-loader/lib/plugin/index-new.js
+2
-1
未找到文件。
packages/webpack-uni-mp-loader/lib/plugin/generate-component.js
浏览文件 @
83c597e9
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
webpack
=
require
(
'
webpack
'
)
const
{
removeExt
,
normalizePath
,
...
...
@@ -121,8 +122,17 @@ module.exports = function generateComponent (compilation, jsonpFunction = 'webpa
if
(
process
.
env
.
UNI_PLATFORM
===
'
mp-alipay
'
)
{
beforeCode
=
'
;my.defineComponent || (my.defineComponent = Component);
'
}
const
source
=
beforeCode
+
origSource
+
`
const
source
=
beforeCode
+
origSource
+
(
webpack
.
version
[
0
]
>
4
?
`
;(
${
globalVar
}
["
${
jsonpFunction
}
"] =
${
globalVar
}
["
${
jsonpFunction
}
"] || []).push([
['
${
chunkName
}
'],
{},
function(__webpack_require__){
__webpack_require__('
${
uniModuleId
}
')['createComponent'](__webpack_require__(
${
JSON
.
stringify
(
moduleId
)}
))
}
]);
`
:
`
;(
${
globalVar
}
["
${
jsonpFunction
}
"] =
${
globalVar
}
["
${
jsonpFunction
}
"] || []).push([
'
${
chunkName
}
',
{
...
...
@@ -133,11 +143,18 @@ module.exports = function generateComponent (compilation, jsonpFunction = 'webpa
[['
${
chunkName
}
']]
]);
`
const
newSource
=
function
()
{
return
source
)
if
(
webpack
.
version
[
0
]
>
4
)
{
const
{
RawSource
}
=
webpack
.
sources
const
newSource
=
new
RawSource
(
source
)
compilation
.
updateAsset
(
name
,
newSource
)
}
else
{
const
newSource
=
function
()
{
return
source
}
newSource
.
__$wrappered
=
true
assets
[
name
].
source
=
newSource
}
newSource
.
__$wrappered
=
true
assets
[
name
].
source
=
newSource
}
}
const
styleExtname
=
getPlatformExts
().
style
...
...
@@ -186,8 +203,14 @@ module.exports = function generateComponent (compilation, jsonpFunction = 'webpa
})
delete
sourceObj
.
componentGenerics
const
source
=
JSON
.
stringify
(
sourceObj
,
null
,
2
)
jsonFile
.
source
=
function
()
{
return
source
if
(
webpack
.
version
[
0
]
>
4
)
{
const
{
RawSource
}
=
webpack
.
sources
const
newSource
=
new
RawSource
(
source
)
compilation
.
updateAsset
(
name
,
newSource
)
}
else
{
jsonFile
.
source
=
function
()
{
return
source
}
}
jsonFile
.
__$oldSource
=
oldSource
}
...
...
@@ -205,8 +228,14 @@ module.exports = function generateComponent (compilation, jsonpFunction = 'webpa
}).
join
(
''
)
})
})
templateFile
.
source
=
function
()
{
return
templateSource
if
(
webpack
.
version
[
0
]
>
4
)
{
const
{
RawSource
}
=
webpack
.
sources
const
newSource
=
new
RawSource
(
templateSource
)
compilation
.
updateAsset
(
name
,
newSource
)
}
else
{
templateFile
.
source
=
function
()
{
return
templateSource
}
}
templateFile
.
__$oldSource
=
oldSource
}
...
...
@@ -215,15 +244,22 @@ module.exports = function generateComponent (compilation, jsonpFunction = 'webpa
})
}
// fix mp-qq https://github.com/dcloudio/uni-app/issues/2648
const
appJsonFile
=
compilation
.
assets
[
'
app.json
'
]
const
appJsonName
=
'
app.json
'
const
appJsonFile
=
compilation
.
assets
[
appJsonName
]
if
(
process
.
env
.
UNI_PLATFORM
===
'
mp-qq
'
&&
appJsonFile
)
{
const
obj
=
JSON
.
parse
(
appJsonFile
.
source
())
if
(
obj
&&
obj
.
usingComponents
&&
!
Object
.
keys
(
obj
.
usingComponents
).
length
)
{
const
componentName
=
'
fix-2648
'
obj
.
usingComponents
[
componentName
]
=
`/
${
componentName
}
`
const
source
=
JSON
.
stringify
(
obj
,
null
,
2
)
appJsonFile
.
source
=
function
()
{
return
source
if
(
webpack
.
version
[
0
]
>
4
)
{
const
{
RawSource
}
=
webpack
.
sources
const
newSource
=
new
RawSource
(
source
)
compilation
.
updateAsset
(
appJsonName
,
newSource
)
}
else
{
appJsonFile
.
source
=
function
()
{
return
source
}
}
const
files
=
[
{
...
...
@@ -258,8 +294,14 @@ module.exports = function generateComponent (compilation, jsonpFunction = 'webpa
const
componentName
=
'
plugin-wrapper
'
obj
.
usingComponents
[
componentName
]
=
`/
${
componentName
}
`
const
source
=
JSON
.
stringify
(
obj
,
null
,
2
)
appJsonFile
.
source
=
function
()
{
return
source
if
(
webpack
.
version
[
0
]
>
4
)
{
const
{
RawSource
}
=
webpack
.
sources
const
newSource
=
new
RawSource
(
source
)
compilation
.
updateAsset
(
appJsonName
,
newSource
)
}
else
{
appJsonFile
.
source
=
function
()
{
return
source
}
}
const
files
=
[
{
...
...
packages/webpack-uni-mp-loader/lib/plugin/index-new.js
浏览文件 @
83c597e9
const
path
=
require
(
'
path
'
)
const
webpack
=
require
(
'
webpack
'
)
const
{
md5
,
...
...
@@ -113,7 +114,7 @@ class WebpackUniMPPlugin {
source
})
=>
emitFile
(
file
,
source
,
compilation
))
generateComponent
(
compilation
,
compiler
.
options
.
output
.
jsonpFunction
)
generateComponent
(
compilation
,
compiler
.
options
.
output
[
webpack
.
version
[
0
]
>
4
?
'
chunkLoadingGlobal
'
:
'
jsonpFunction
'
]
)
resolve
()
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录