@mpxjs/webpack-plugin 2.7.17 → 2.7.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +95 -106
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -969,46 +969,6 @@ class MpxWebpackPlugin {
|
|
|
969
969
|
stage: -1000
|
|
970
970
|
}, (expr, calleeMembers, callExpr) => requireAsyncHandler(callExpr, calleeMembers))
|
|
971
971
|
|
|
972
|
-
const transHandler = (expr) => {
|
|
973
|
-
const module = parser.state.module
|
|
974
|
-
const current = parser.state.current
|
|
975
|
-
const { queryObj, resourcePath } = parseRequest(module.resource)
|
|
976
|
-
const localSrcMode = queryObj.mode
|
|
977
|
-
const globalSrcMode = mpx.srcMode
|
|
978
|
-
const srcMode = localSrcMode || globalSrcMode
|
|
979
|
-
const mode = mpx.mode
|
|
980
|
-
|
|
981
|
-
let target
|
|
982
|
-
|
|
983
|
-
if (expr.type === 'Identifier') {
|
|
984
|
-
target = expr
|
|
985
|
-
} else if (expr.type === 'MemberExpression') {
|
|
986
|
-
target = expr.object
|
|
987
|
-
}
|
|
988
|
-
if (!matchCondition(resourcePath, this.options.transMpxRules) || resourcePath.indexOf('@mpxjs') !== -1 || !target || mode === srcMode) {
|
|
989
|
-
return
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
const type = target.name
|
|
993
|
-
|
|
994
|
-
const name = type === 'wx' ? 'mpx' : 'createFactory'
|
|
995
|
-
const replaceContent = type === 'wx' ? 'mpx' : `createFactory(${JSON.stringify(type)})`
|
|
996
|
-
|
|
997
|
-
const dep = new ReplaceDependency(replaceContent, target.range)
|
|
998
|
-
current.addPresentationalDependency(dep)
|
|
999
|
-
|
|
1000
|
-
let needInject = true
|
|
1001
|
-
for (let dep of module.dependencies) {
|
|
1002
|
-
if (dep instanceof CommonJsVariableDependency && dep.name === name) {
|
|
1003
|
-
needInject = false
|
|
1004
|
-
break
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
if (needInject) {
|
|
1008
|
-
const dep = new CommonJsVariableDependency(`@mpxjs/core/src/runtime/${name}`, name)
|
|
1009
|
-
module.addDependency(dep)
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
972
|
// hack babel polyfill global
|
|
1013
973
|
parser.hooks.statementIf.tap('MpxWebpackPlugin', (expr) => {
|
|
1014
974
|
if (/core-js.+microtask/.test(parser.state.module.resource)) {
|
|
@@ -1043,90 +1003,119 @@ class MpxWebpackPlugin {
|
|
|
1043
1003
|
}
|
|
1044
1004
|
})
|
|
1045
1005
|
|
|
1006
|
+
// 处理跨平台转换
|
|
1046
1007
|
if (mpx.srcMode !== mpx.mode) {
|
|
1047
|
-
//
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1008
|
+
// 处理跨平台全局对象转换
|
|
1009
|
+
const transGlobalObject = (expr) => {
|
|
1010
|
+
const module = parser.state.module
|
|
1011
|
+
const current = parser.state.current
|
|
1012
|
+
const { queryObj, resourcePath } = parseRequest(module.resource)
|
|
1013
|
+
const localSrcMode = queryObj.mode
|
|
1014
|
+
const globalSrcMode = mpx.srcMode
|
|
1015
|
+
const srcMode = localSrcMode || globalSrcMode
|
|
1016
|
+
const mode = mpx.mode
|
|
1017
|
+
|
|
1018
|
+
let target
|
|
1019
|
+
if (expr.type === 'Identifier') {
|
|
1020
|
+
target = expr
|
|
1021
|
+
} else if (expr.type === 'MemberExpression') {
|
|
1022
|
+
target = expr.object
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
if (!matchCondition(resourcePath, this.options.transMpxRules) || resourcePath.indexOf('@mpxjs') !== -1 || !target || mode === srcMode) return
|
|
1026
|
+
|
|
1027
|
+
const type = target.name
|
|
1028
|
+
const name = type === 'wx' ? 'mpx' : 'createFactory'
|
|
1029
|
+
const replaceContent = type === 'wx' ? 'mpx' : `createFactory(${JSON.stringify(type)})`
|
|
1030
|
+
|
|
1031
|
+
const dep = new ReplaceDependency(replaceContent, target.range)
|
|
1032
|
+
current.addPresentationalDependency(dep)
|
|
1033
|
+
|
|
1034
|
+
let needInject = true
|
|
1035
|
+
for (let dep of module.dependencies) {
|
|
1036
|
+
if (dep instanceof CommonJsVariableDependency && dep.name === name) {
|
|
1037
|
+
needInject = false
|
|
1038
|
+
break
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
if (needInject) {
|
|
1042
|
+
const dep = new CommonJsVariableDependency(`@mpxjs/core/src/runtime/${name}`, name)
|
|
1043
|
+
module.addDependency(dep)
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
// 转换wx全局对象
|
|
1048
|
+
parser.hooks.expression.for('wx').tap('MpxWebpackPlugin', transGlobalObject)
|
|
1059
1049
|
// Proxy ctor for transMode
|
|
1060
1050
|
if (!this.options.forceDisableProxyCtor) {
|
|
1061
1051
|
parser.hooks.call.for('Page').tap('MpxWebpackPlugin', (expr) => {
|
|
1062
|
-
|
|
1052
|
+
transGlobalObject(expr.callee)
|
|
1063
1053
|
})
|
|
1064
1054
|
parser.hooks.call.for('Component').tap('MpxWebpackPlugin', (expr) => {
|
|
1065
|
-
|
|
1055
|
+
transGlobalObject(expr.callee)
|
|
1066
1056
|
})
|
|
1067
1057
|
parser.hooks.call.for('App').tap('MpxWebpackPlugin', (expr) => {
|
|
1068
|
-
|
|
1058
|
+
transGlobalObject(expr.callee)
|
|
1069
1059
|
})
|
|
1070
1060
|
if (mpx.mode === 'ali' || mpx.mode === 'web') {
|
|
1071
1061
|
// 支付宝和web不支持Behaviors
|
|
1072
1062
|
parser.hooks.call.for('Behavior').tap('MpxWebpackPlugin', (expr) => {
|
|
1073
|
-
|
|
1063
|
+
transGlobalObject(expr.callee)
|
|
1074
1064
|
})
|
|
1075
1065
|
}
|
|
1076
1066
|
}
|
|
1077
|
-
}
|
|
1078
1067
|
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
map
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
const handler = (expr) => {
|
|
1104
|
-
const callee = expr.callee
|
|
1105
|
-
const args = expr.arguments
|
|
1106
|
-
const name = callee.object.name
|
|
1107
|
-
const { queryObj, resourcePath } = parseRequest(parser.state.module.resource)
|
|
1108
|
-
const localSrcMode = queryObj.mode
|
|
1109
|
-
const globalSrcMode = mpx.srcMode
|
|
1110
|
-
const srcMode = localSrcMode || globalSrcMode
|
|
1111
|
-
|
|
1112
|
-
if (srcMode === globalSrcMode || apiBlackListMap[callee.property.name || callee.property.value] || (name !== 'mpx' && name !== 'wx') || (name === 'wx' && !matchCondition(resourcePath, this.options.transMpxRules))) {
|
|
1113
|
-
return
|
|
1114
|
-
}
|
|
1068
|
+
// 为跨平台api调用注入srcMode参数指导api运行时转换
|
|
1069
|
+
const apiBlackListMap = [
|
|
1070
|
+
'createApp',
|
|
1071
|
+
'createPage',
|
|
1072
|
+
'createComponent',
|
|
1073
|
+
'createStore',
|
|
1074
|
+
'createStoreWithThis',
|
|
1075
|
+
'mixin',
|
|
1076
|
+
'injectMixins',
|
|
1077
|
+
'toPureObject',
|
|
1078
|
+
'observable',
|
|
1079
|
+
'watch',
|
|
1080
|
+
'use',
|
|
1081
|
+
'set',
|
|
1082
|
+
'remove',
|
|
1083
|
+
'delete',
|
|
1084
|
+
'setConvertRule',
|
|
1085
|
+
'getMixin',
|
|
1086
|
+
'getComputed',
|
|
1087
|
+
'implement'
|
|
1088
|
+
].reduce((map, api) => {
|
|
1089
|
+
map[api] = true
|
|
1090
|
+
return map
|
|
1091
|
+
}, {})
|
|
1115
1092
|
|
|
1116
|
-
const
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1093
|
+
const injectSrcModeForTransApi = (expr, members) => {
|
|
1094
|
+
// members为空数组时,callee并不是memberExpression
|
|
1095
|
+
if (!members.length) return
|
|
1096
|
+
const callee = expr.callee
|
|
1097
|
+
const args = expr.arguments
|
|
1098
|
+
const name = callee.object.name
|
|
1099
|
+
const { queryObj, resourcePath } = parseRequest(parser.state.module.resource)
|
|
1100
|
+
const localSrcMode = queryObj.mode
|
|
1101
|
+
const globalSrcMode = mpx.srcMode
|
|
1102
|
+
const srcMode = localSrcMode || globalSrcMode
|
|
1103
|
+
|
|
1104
|
+
if (srcMode === globalSrcMode || apiBlackListMap[callee.property.name || callee.property.value] || (name !== 'mpx' && name !== 'wx') || (name === 'wx' && !matchCondition(resourcePath, this.options.transMpxRules))) return
|
|
1105
|
+
|
|
1106
|
+
const srcModeString = `__mpx_src_mode_${srcMode}__`
|
|
1107
|
+
const dep = new InjectDependency({
|
|
1108
|
+
content: args.length
|
|
1109
|
+
? `, ${JSON.stringify(srcModeString)}`
|
|
1110
|
+
: JSON.stringify(srcModeString),
|
|
1111
|
+
index: expr.end - 1
|
|
1112
|
+
})
|
|
1113
|
+
parser.state.current.addPresentationalDependency(dep)
|
|
1114
|
+
}
|
|
1125
1115
|
|
|
1126
|
-
|
|
1127
|
-
parser.hooks.callMemberChain.for(
|
|
1128
|
-
parser.hooks.callMemberChain.for('
|
|
1129
|
-
parser.hooks.callMemberChain.for('wx').tap('MpxWebpackPlugin', handler)
|
|
1116
|
+
parser.hooks.callMemberChain.for(harmonySpecifierTag).tap('MpxWebpackPlugin', injectSrcModeForTransApi)
|
|
1117
|
+
parser.hooks.callMemberChain.for('mpx').tap('MpxWebpackPlugin', injectSrcModeForTransApi)
|
|
1118
|
+
parser.hooks.callMemberChain.for('wx').tap('MpxWebpackPlugin', injectSrcModeForTransApi)
|
|
1130
1119
|
}
|
|
1131
1120
|
})
|
|
1132
1121
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.18",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=14.14.0"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "5cca51d77d97143319c895dab301ef9a789ce40f"
|
|
84
84
|
}
|