@mpxjs/webpack-plugin 2.8.57 → 2.8.60
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 +3 -10
- package/lib/template-compiler/bind-this.js +37 -11
- package/lib/template-compiler/compiler.js +103 -67
- package/lib/template-compiler/index.js +32 -35
- package/lib/web/processTemplate.js +1 -11
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -125,7 +125,6 @@ class MpxWebpackPlugin {
|
|
|
125
125
|
options.resolveMode = options.resolveMode || 'webpack'
|
|
126
126
|
options.writeMode = options.writeMode || 'changed'
|
|
127
127
|
options.autoScopeRules = options.autoScopeRules || {}
|
|
128
|
-
options.renderOptimizeRules = options.renderOptimizeRules || {}
|
|
129
128
|
options.autoVirtualHostRules = options.autoVirtualHostRules || {}
|
|
130
129
|
options.forceDisableProxyCtor = options.forceDisableProxyCtor || false
|
|
131
130
|
options.transMpxRules = options.transMpxRules || {
|
|
@@ -169,16 +168,11 @@ class MpxWebpackPlugin {
|
|
|
169
168
|
}, options.nativeConfig)
|
|
170
169
|
options.webConfig = options.webConfig || {}
|
|
171
170
|
options.partialCompile = options.mode !== 'web' && options.partialCompile
|
|
172
|
-
options.asyncSubpackageRules = options.asyncSubpackageRules ||
|
|
171
|
+
options.asyncSubpackageRules = options.asyncSubpackageRules || []
|
|
172
|
+
options.optimizeRenderRules = options.optimizeRenderRules || {}
|
|
173
173
|
options.retryRequireAsync = options.retryRequireAsync || false
|
|
174
174
|
options.enableAliRequireAsync = options.enableAliRequireAsync || false
|
|
175
175
|
options.optimizeSize = options.optimizeSize || false
|
|
176
|
-
let proxyComponentEventsRules = []
|
|
177
|
-
const proxyComponentEventsRulesRaw = options.proxyComponentEventsRules
|
|
178
|
-
if (proxyComponentEventsRulesRaw) {
|
|
179
|
-
proxyComponentEventsRules = Array.isArray(proxyComponentEventsRulesRaw) ? proxyComponentEventsRulesRaw : [proxyComponentEventsRulesRaw]
|
|
180
|
-
}
|
|
181
|
-
options.proxyComponentEventsRules = proxyComponentEventsRules
|
|
182
176
|
this.options = options
|
|
183
177
|
// Hack for buildDependencies
|
|
184
178
|
const rawResolveBuildDependencies = FileSystemInfo.prototype.resolveBuildDependencies
|
|
@@ -639,14 +633,13 @@ class MpxWebpackPlugin {
|
|
|
639
633
|
appTitle: 'Mpx homepage',
|
|
640
634
|
attributes: this.options.attributes,
|
|
641
635
|
externals: this.options.externals,
|
|
642
|
-
renderOptimizeRules: this.options.renderOptimizeRules,
|
|
643
636
|
useRelativePath: this.options.useRelativePath,
|
|
644
637
|
removedChunks: [],
|
|
645
638
|
forceProxyEventRules: this.options.forceProxyEventRules,
|
|
646
639
|
enableRequireAsync: this.options.mode === 'wx' || (this.options.mode === 'ali' && this.options.enableAliRequireAsync),
|
|
647
640
|
partialCompile: this.options.partialCompile,
|
|
648
641
|
asyncSubpackageRules: this.options.asyncSubpackageRules,
|
|
649
|
-
|
|
642
|
+
optimizeRenderRules: this.options.optimizeRenderRules,
|
|
650
643
|
pathHash: (resourcePath) => {
|
|
651
644
|
if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
|
|
652
645
|
return hash(path.relative(this.options.projectRoot, resourcePath))
|
|
@@ -85,7 +85,7 @@ function checkDelAndGetPath (path) {
|
|
|
85
85
|
if (args.length === 1) {
|
|
86
86
|
delPath = current.parentPath
|
|
87
87
|
} else {
|
|
88
|
-
// case:
|
|
88
|
+
// case: _i(a, function() {})
|
|
89
89
|
canDel = false
|
|
90
90
|
break
|
|
91
91
|
}
|
|
@@ -96,6 +96,16 @@ function checkDelAndGetPath (path) {
|
|
|
96
96
|
} else {
|
|
97
97
|
delPath = current.parentPath
|
|
98
98
|
}
|
|
99
|
+
} else if (t.isLogicalExpression(current.container)) { // case: a || ''
|
|
100
|
+
const key = current.key === 'left' ? 'right' : 'left'
|
|
101
|
+
if (t.isLiteral(current.parent[key])) {
|
|
102
|
+
delPath = current.parentPath
|
|
103
|
+
} else {
|
|
104
|
+
canDel = false
|
|
105
|
+
break
|
|
106
|
+
}
|
|
107
|
+
} else if (current.key === 'expression' && t.isExpressionStatement(current.parentPath)) { // dealRemove删除节点时需要
|
|
108
|
+
delPath = current.parentPath
|
|
99
109
|
} else {
|
|
100
110
|
break
|
|
101
111
|
}
|
|
@@ -152,10 +162,6 @@ function checkPrefix (keys, key) {
|
|
|
152
162
|
}
|
|
153
163
|
|
|
154
164
|
function dealRemove (path, replace) {
|
|
155
|
-
while (path.key === 'expression' && t.isExpressionStatement(path.parentPath)) {
|
|
156
|
-
path = path.parentPath
|
|
157
|
-
}
|
|
158
|
-
|
|
159
165
|
try {
|
|
160
166
|
if (replace) {
|
|
161
167
|
path.replaceWith(t.stringLiteral(''))
|
|
@@ -163,8 +169,9 @@ function dealRemove (path, replace) {
|
|
|
163
169
|
t.validate(path, path.key, null)
|
|
164
170
|
path.remove()
|
|
165
171
|
}
|
|
172
|
+
delete path.needBind
|
|
173
|
+
delete path.collectPath
|
|
166
174
|
} catch (e) {
|
|
167
|
-
console.error(e)
|
|
168
175
|
}
|
|
169
176
|
}
|
|
170
177
|
|
|
@@ -202,9 +209,23 @@ module.exports = {
|
|
|
202
209
|
Identifier (path) {
|
|
203
210
|
if (
|
|
204
211
|
checkBindThis(path) &&
|
|
205
|
-
!path.scope.hasBinding(path.node.name) &&
|
|
206
212
|
!ignoreMap[path.node.name]
|
|
207
213
|
) {
|
|
214
|
+
const scopeBinding = path.scope.hasBinding(path.node.name)
|
|
215
|
+
// 删除局部作用域的变量
|
|
216
|
+
if (scopeBinding) {
|
|
217
|
+
if (renderReduce) {
|
|
218
|
+
const { delPath, canDel, ignore, replace } = checkDelAndGetPath(path)
|
|
219
|
+
if (canDel && !ignore) {
|
|
220
|
+
delPath.delInfo = {
|
|
221
|
+
isLocal: true,
|
|
222
|
+
canDel,
|
|
223
|
+
replace
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return
|
|
228
|
+
}
|
|
208
229
|
const { last, keyPath } = calPropName(path)
|
|
209
230
|
path.needBind = true
|
|
210
231
|
if (needCollect) {
|
|
@@ -272,10 +293,14 @@ module.exports = {
|
|
|
272
293
|
enter (path) {
|
|
273
294
|
// 删除重复变量
|
|
274
295
|
if (path.delInfo) {
|
|
275
|
-
const { keyPath, canDel, replace } = path.delInfo
|
|
296
|
+
const { keyPath, canDel, isLocal, replace } = path.delInfo
|
|
276
297
|
delete path.delInfo
|
|
277
298
|
|
|
278
299
|
if (canDel) {
|
|
300
|
+
if (isLocal) { // 局部作用域里的变量,可直接删除
|
|
301
|
+
dealRemove(path, replace)
|
|
302
|
+
return
|
|
303
|
+
}
|
|
279
304
|
const data = bindingsMap.get(currentBlock)
|
|
280
305
|
const { bindings, pBindings } = data
|
|
281
306
|
const allBindings = Object.assign({}, pBindings, bindings)
|
|
@@ -283,14 +308,12 @@ module.exports = {
|
|
|
283
308
|
// 优先判断前缀,再判断全等
|
|
284
309
|
if (checkPrefix(Object.keys(allBindings), keyPath) || pBindings[keyPath]) {
|
|
285
310
|
dealRemove(path, replace)
|
|
286
|
-
return
|
|
287
311
|
} else {
|
|
288
312
|
const currentBlockVars = bindings[keyPath]
|
|
289
313
|
if (currentBlockVars.length > 1) {
|
|
290
314
|
const index = currentBlockVars.findIndex(item => !item.canDel)
|
|
291
315
|
if (index !== -1 || currentBlockVars[0].path !== path) { // 当前block中存在不可删除的变量 || 不是第一个可删除变量,即可删除该变量
|
|
292
316
|
dealRemove(path, replace)
|
|
293
|
-
return
|
|
294
317
|
}
|
|
295
318
|
}
|
|
296
319
|
}
|
|
@@ -312,7 +335,10 @@ module.exports = {
|
|
|
312
335
|
MemberExpression: {
|
|
313
336
|
exit (path) {
|
|
314
337
|
if (path.collectPath) {
|
|
315
|
-
|
|
338
|
+
const replaceNode = renderReduce
|
|
339
|
+
? t.callExpression(t.identifier('_c'), [path.collectPath])
|
|
340
|
+
: t.callExpression(t.identifier('_c'), [path.collectPath, path.node])
|
|
341
|
+
path.node && path.replaceWith(replaceNode)
|
|
316
342
|
delete path.collectPath
|
|
317
343
|
}
|
|
318
344
|
}
|
|
@@ -3,6 +3,7 @@ const he = require('he')
|
|
|
3
3
|
const config = require('../config')
|
|
4
4
|
const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../utils/const')
|
|
5
5
|
const normalize = require('../utils/normalize')
|
|
6
|
+
const { normalizeCondition } = require('../utils/match-condition')
|
|
6
7
|
const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
|
|
7
8
|
const isEmptyObject = require('../utils/is-empty-object')
|
|
8
9
|
const getRulesRunner = require('../platform/index')
|
|
@@ -1090,6 +1091,7 @@ function processBindEvent (el, options) {
|
|
|
1090
1091
|
for (const type in eventConfigMap) {
|
|
1091
1092
|
let needBind = false
|
|
1092
1093
|
let { configs, rawName, proxy } = eventConfigMap[type]
|
|
1094
|
+
delete eventConfigMap[type]
|
|
1093
1095
|
if (proxy) {
|
|
1094
1096
|
needBind = true
|
|
1095
1097
|
} else if (configs.length > 1) {
|
|
@@ -1097,11 +1099,14 @@ function processBindEvent (el, options) {
|
|
|
1097
1099
|
} else if (configs.length === 1) {
|
|
1098
1100
|
needBind = !!configs[0].hasArgs
|
|
1099
1101
|
}
|
|
1102
|
+
|
|
1103
|
+
const escapedType = dash2hump(type)
|
|
1100
1104
|
// 排除特殊情况
|
|
1101
|
-
if (
|
|
1105
|
+
if (!isValidIdentifierStr(escapedType)) {
|
|
1102
1106
|
warn$1(`EventName ${type} which need be framework proxy processed must be a valid identifier!`)
|
|
1103
1107
|
needBind = false
|
|
1104
1108
|
}
|
|
1109
|
+
|
|
1105
1110
|
if (needBind) {
|
|
1106
1111
|
if (rawName) {
|
|
1107
1112
|
// 清空原始事件绑定
|
|
@@ -1119,11 +1124,9 @@ function processBindEvent (el, options) {
|
|
|
1119
1124
|
value: '__invoke'
|
|
1120
1125
|
}
|
|
1121
1126
|
])
|
|
1122
|
-
eventConfigMap[
|
|
1127
|
+
eventConfigMap[escapedType] = configs.map((item) => {
|
|
1123
1128
|
return item.expStr
|
|
1124
1129
|
})
|
|
1125
|
-
} else {
|
|
1126
|
-
delete eventConfigMap[type]
|
|
1127
1130
|
}
|
|
1128
1131
|
}
|
|
1129
1132
|
|
|
@@ -1750,68 +1753,105 @@ function processBuiltInComponents (el, meta) {
|
|
|
1750
1753
|
}
|
|
1751
1754
|
}
|
|
1752
1755
|
|
|
1753
|
-
function
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1756
|
+
function processAliAddComponentRootView (el, options) {
|
|
1757
|
+
const processAttrsConditions = [
|
|
1758
|
+
{ condition: /^(on|catch)Tap$/, action: 'clone' },
|
|
1759
|
+
{ condition: /^(on|catch)TouchStart$/, action: 'clone' },
|
|
1760
|
+
{ condition: /^(on|catch)TouchMove$/, action: 'clone' },
|
|
1761
|
+
{ condition: /^(on|catch)TouchEnd$/, action: 'clone' },
|
|
1762
|
+
{ condition: /^(on|catch)TouchCancel$/, action: 'clone' },
|
|
1763
|
+
{ condition: /^(on|catch)LongTap$/, action: 'clone' },
|
|
1764
|
+
{ condition: /^data-/, action: 'clone' },
|
|
1765
|
+
{ condition: /^id$/, action: 'clone' },
|
|
1766
|
+
{ condition: /^style$/, action: 'move' },
|
|
1767
|
+
{ condition: /^slot$/, action: 'move' }
|
|
1768
|
+
]
|
|
1769
|
+
const processAppendAttrsRules = [
|
|
1770
|
+
{ name: 'class', value: `${MPX_ROOT_VIEW} host-${options.moduleId}` }
|
|
1771
|
+
]
|
|
1772
|
+
const newElAttrs = []
|
|
1773
|
+
const allAttrs = cloneAttrsList(el.attrsList)
|
|
1774
|
+
|
|
1775
|
+
function processClone (attr) {
|
|
1776
|
+
newElAttrs.push(attr)
|
|
1766
1777
|
}
|
|
1767
|
-
}
|
|
1768
1778
|
|
|
1769
|
-
function
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
const sep = name === 'style' ? ';' : ' '
|
|
1774
|
-
value = value ? `{{${typeName}||''}}${sep}${value}` : `{{${typeName}||''}}`
|
|
1775
|
-
return [name, value]
|
|
1776
|
-
}
|
|
1779
|
+
function processMove (attr) {
|
|
1780
|
+
getAndRemoveAttr(el, attr.name)
|
|
1781
|
+
newElAttrs.push(attr)
|
|
1782
|
+
}
|
|
1777
1783
|
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
const
|
|
1781
|
-
const
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1784
|
+
function processAppendRules (el) {
|
|
1785
|
+
processAppendAttrsRules.forEach((rule) => {
|
|
1786
|
+
const getNeedAppendAttrValue = el.attrsMap[rule.name]
|
|
1787
|
+
const value = getNeedAppendAttrValue ? getNeedAppendAttrValue + ' ' + rule.value : rule.value
|
|
1788
|
+
newElAttrs.push({
|
|
1789
|
+
name: rule.name,
|
|
1790
|
+
value
|
|
1785
1791
|
})
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1792
|
+
})
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
processAttrsConditions.forEach(item => {
|
|
1796
|
+
const matcher = normalizeCondition(item.condition)
|
|
1797
|
+
allAttrs.forEach((attr) => {
|
|
1798
|
+
if (matcher(attr.name)) {
|
|
1799
|
+
if (item.action === 'clone') {
|
|
1800
|
+
processClone(attr)
|
|
1801
|
+
} else if (item.action === 'move') {
|
|
1802
|
+
processMove(attr)
|
|
1803
|
+
}
|
|
1791
1804
|
}
|
|
1792
1805
|
})
|
|
1806
|
+
})
|
|
1807
|
+
|
|
1808
|
+
processAppendRules(el)
|
|
1809
|
+
const componentWrapView = createASTElement('view', newElAttrs)
|
|
1810
|
+
moveBaseDirective(componentWrapView, el)
|
|
1811
|
+
if (el.is && el.components) {
|
|
1812
|
+
el = postProcessComponentIs(el)
|
|
1793
1813
|
}
|
|
1814
|
+
|
|
1815
|
+
replaceNode(el, componentWrapView, true)
|
|
1816
|
+
addChild(componentWrapView, el)
|
|
1817
|
+
return componentWrapView
|
|
1794
1818
|
}
|
|
1795
1819
|
|
|
1796
1820
|
// 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
|
|
1797
1821
|
function getVirtualHostRoot (options, meta) {
|
|
1798
|
-
if (srcMode === 'wx'
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1822
|
+
if (srcMode === 'wx') {
|
|
1823
|
+
if (options.isComponent) {
|
|
1824
|
+
if ((mode === 'wx') && options.hasVirtualHost) {
|
|
1825
|
+
// wx组件注入virtualHost配置
|
|
1826
|
+
!meta.options && (meta.options = {})
|
|
1827
|
+
meta.options.virtualHost = true
|
|
1828
|
+
}
|
|
1829
|
+
if ((mode === 'web') && !options.hasVirtualHost) {
|
|
1830
|
+
// ali组件根节点实体化
|
|
1831
|
+
const rootView = createASTElement('view', [
|
|
1832
|
+
{
|
|
1833
|
+
name: 'class',
|
|
1834
|
+
value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
|
|
1835
|
+
},
|
|
1836
|
+
{
|
|
1837
|
+
name: 'v-on',
|
|
1838
|
+
value: '$listeners'
|
|
1839
|
+
}
|
|
1840
|
+
])
|
|
1841
|
+
rootView.hasEvent = true
|
|
1842
|
+
processElement(rootView, rootView, options, meta)
|
|
1843
|
+
return rootView
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
if (options.isPage) {
|
|
1847
|
+
if (mode === 'web') {
|
|
1848
|
+
return createASTElement('div', [
|
|
1849
|
+
{
|
|
1850
|
+
name: 'class',
|
|
1851
|
+
value: 'page'
|
|
1852
|
+
}
|
|
1853
|
+
])
|
|
1854
|
+
}
|
|
1815
1855
|
}
|
|
1816
1856
|
}
|
|
1817
1857
|
return getTempNode()
|
|
@@ -1991,16 +2031,6 @@ function processMpxTagName (el) {
|
|
|
1991
2031
|
}
|
|
1992
2032
|
|
|
1993
2033
|
function processElement (el, root, options, meta) {
|
|
1994
|
-
const transAli = mode === 'ali' && srcMode === 'wx'
|
|
1995
|
-
const transWeb = mode === 'web' && srcMode === 'wx'
|
|
1996
|
-
if (transAli) {
|
|
1997
|
-
processRootViewStyleClassHack(el, options, root)
|
|
1998
|
-
processRootViewEventHack(el, options, root)
|
|
1999
|
-
}
|
|
2000
|
-
if (transWeb) {
|
|
2001
|
-
processRootViewEventHack(el, options, root)
|
|
2002
|
-
}
|
|
2003
|
-
|
|
2004
2034
|
processAtMode(el)
|
|
2005
2035
|
// 如果已经标记了这个元素要被清除,直接return跳过后续处理步骤
|
|
2006
2036
|
if (el._atModeStatus === 'mismatch') {
|
|
@@ -2020,6 +2050,8 @@ function processElement (el, root, options, meta) {
|
|
|
2020
2050
|
|
|
2021
2051
|
processInjectWxs(el, meta)
|
|
2022
2052
|
|
|
2053
|
+
const transAli = mode === 'ali' && srcMode === 'wx'
|
|
2054
|
+
|
|
2023
2055
|
if (mode === 'web') {
|
|
2024
2056
|
// 收集内建组件
|
|
2025
2057
|
processBuiltInComponents(el, meta)
|
|
@@ -2071,7 +2103,11 @@ function closeElement (el, meta, options) {
|
|
|
2071
2103
|
postProcessWxs(el, meta)
|
|
2072
2104
|
|
|
2073
2105
|
if (!pass) {
|
|
2074
|
-
|
|
2106
|
+
if (isComponentNode(el, options) && !options.hasVirtualHost && mode === 'ali') {
|
|
2107
|
+
el = processAliAddComponentRootView(el, options)
|
|
2108
|
+
} else {
|
|
2109
|
+
el = postProcessComponentIs(el)
|
|
2110
|
+
}
|
|
2075
2111
|
}
|
|
2076
2112
|
postProcessFor(el)
|
|
2077
2113
|
postProcessIf(el)
|
|
@@ -2287,7 +2323,7 @@ function genFor (node) {
|
|
|
2287
2323
|
node.forProcessed = true
|
|
2288
2324
|
const index = node.for.index || 'index'
|
|
2289
2325
|
const item = node.for.item || 'item'
|
|
2290
|
-
return `
|
|
2326
|
+
return `_i(${node.for.exp}, function(${item},${index}){\n${genNode(node)}});\n`
|
|
2291
2327
|
}
|
|
2292
2328
|
|
|
2293
2329
|
function genNode (node) {
|
|
@@ -19,8 +19,9 @@ module.exports = function (raw) {
|
|
|
19
19
|
const localSrcMode = queryObj.mode
|
|
20
20
|
const packageName = queryObj.packageRoot || mpx.currentPackageRoot || 'main'
|
|
21
21
|
const componentsMap = mpx.componentsMap[packageName]
|
|
22
|
+
const pagesMap = mpx.pagesMap
|
|
22
23
|
const wxsContentMap = mpx.wxsContentMap
|
|
23
|
-
const
|
|
24
|
+
const optimizeRenderRules = mpx.optimizeRenderRules
|
|
24
25
|
const usingComponents = queryObj.usingComponents || []
|
|
25
26
|
const componentPlaceholder = queryObj.componentPlaceholder || []
|
|
26
27
|
const hasComment = queryObj.hasComment
|
|
@@ -40,14 +41,6 @@ module.exports = function (raw) {
|
|
|
40
41
|
)
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
let proxyComponentEvents = null
|
|
44
|
-
for (const item of mpx.proxyComponentEventsRules) {
|
|
45
|
-
if (matchCondition(resourcePath, item)) {
|
|
46
|
-
const eventsRaw = item.events
|
|
47
|
-
proxyComponentEvents = Array.isArray(eventsRaw) ? eventsRaw : [eventsRaw]
|
|
48
|
-
break
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
44
|
const { root: ast, meta } = compiler.parse(raw, {
|
|
52
45
|
warn,
|
|
53
46
|
error,
|
|
@@ -56,6 +49,7 @@ module.exports = function (raw) {
|
|
|
56
49
|
hasComment,
|
|
57
50
|
isNative,
|
|
58
51
|
isComponent: !!componentsMap[resourcePath],
|
|
52
|
+
isPage: !!pagesMap[resourcePath],
|
|
59
53
|
mode,
|
|
60
54
|
env,
|
|
61
55
|
srcMode: localSrcMode || globalSrcMode,
|
|
@@ -70,8 +64,7 @@ module.exports = function (raw) {
|
|
|
70
64
|
checkUsingComponents: matchCondition(resourcePath, mpx.checkUsingComponentsRules),
|
|
71
65
|
globalComponents: Object.keys(mpx.usingComponents),
|
|
72
66
|
forceProxyEvent: matchCondition(resourcePath, mpx.forceProxyEventRules),
|
|
73
|
-
hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules)
|
|
74
|
-
proxyComponentEvents
|
|
67
|
+
hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules)
|
|
75
68
|
})
|
|
76
69
|
|
|
77
70
|
if (meta.wxsContentMap) {
|
|
@@ -93,39 +86,43 @@ module.exports = function (raw) {
|
|
|
93
86
|
return result
|
|
94
87
|
}
|
|
95
88
|
|
|
96
|
-
|
|
89
|
+
resultSource += `
|
|
97
90
|
global.currentInject = {
|
|
98
|
-
moduleId: ${JSON.stringify(moduleId)}
|
|
99
|
-
render: function () {
|
|
100
|
-
${compiler.genNode(ast)}
|
|
101
|
-
this._r();
|
|
102
|
-
}
|
|
91
|
+
moduleId: ${JSON.stringify(moduleId)}
|
|
103
92
|
};\n`
|
|
104
93
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
94
|
+
const rawCode = compiler.genNode(ast)
|
|
95
|
+
if (rawCode) {
|
|
96
|
+
const renderCode = `
|
|
97
|
+
global.currentInject.render = function (_i, _c, _r) {
|
|
98
|
+
${rawCode}
|
|
99
|
+
_r();
|
|
100
|
+
};\n`
|
|
101
|
+
try {
|
|
102
|
+
const bindResult = bindThis(renderCode, {
|
|
103
|
+
needCollect: true,
|
|
104
|
+
renderReduce: matchCondition(resourcePath, optimizeRenderRules),
|
|
105
|
+
ignoreMap: Object.assign({
|
|
106
|
+
_i: true,
|
|
107
|
+
_c: true,
|
|
108
|
+
_r: true
|
|
109
|
+
}, meta.wxsModuleMap)
|
|
110
|
+
})
|
|
111
|
+
resultSource += bindResult.code
|
|
112
|
+
if ((mode === 'tt' || mode === 'swan') && bindResult.propKeys) {
|
|
113
|
+
resultSource += `global.currentInject.propKeys = ${JSON.stringify(bindResult.propKeys)};\n`
|
|
114
|
+
}
|
|
115
|
+
} catch (e) {
|
|
116
|
+
error(`
|
|
115
117
|
Invalid render function generated by the template, please check!\n
|
|
116
118
|
Template result:
|
|
117
119
|
${result}\n
|
|
118
120
|
Error code:
|
|
119
|
-
${
|
|
121
|
+
${renderCode}
|
|
120
122
|
Error Detail:
|
|
121
123
|
${e.stack}`)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
resultSource += bindResult.code + '\n'
|
|
126
|
-
|
|
127
|
-
if ((mode === 'tt' || mode === 'swan') && bindResult.propKeys) {
|
|
128
|
-
resultSource += `global.currentInject.propKeys = ${JSON.stringify(bindResult.propKeys)};\n`
|
|
124
|
+
return result
|
|
125
|
+
}
|
|
129
126
|
}
|
|
130
127
|
|
|
131
128
|
if (meta.computed) {
|
|
@@ -23,7 +23,6 @@ module.exports = function (template, {
|
|
|
23
23
|
decodeHTMLText,
|
|
24
24
|
externalClasses,
|
|
25
25
|
checkUsingComponents,
|
|
26
|
-
proxyComponentEventsRules,
|
|
27
26
|
autoVirtualHostRules
|
|
28
27
|
} = mpx
|
|
29
28
|
const { resourcePath } = parseRequest(loaderContext.resource)
|
|
@@ -58,15 +57,6 @@ module.exports = function (template, {
|
|
|
58
57
|
if (template.content) {
|
|
59
58
|
const templateSrcMode = template.mode || srcMode
|
|
60
59
|
|
|
61
|
-
let proxyComponentEvents = null
|
|
62
|
-
for (const item of proxyComponentEventsRules) {
|
|
63
|
-
if (matchCondition(resourcePath, item)) {
|
|
64
|
-
const eventsRaw = item.events
|
|
65
|
-
proxyComponentEvents = Array.isArray(eventsRaw) ? eventsRaw : [eventsRaw]
|
|
66
|
-
break
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
60
|
const { root, meta } = templateCompiler.parse(template.content, {
|
|
71
61
|
warn: (msg) => {
|
|
72
62
|
loaderContext.emitWarning(
|
|
@@ -82,6 +72,7 @@ module.exports = function (template, {
|
|
|
82
72
|
hasComment,
|
|
83
73
|
isNative,
|
|
84
74
|
isComponent: ctorType === 'component',
|
|
75
|
+
isPage: ctorType === 'page',
|
|
85
76
|
mode,
|
|
86
77
|
srcMode: templateSrcMode,
|
|
87
78
|
defs,
|
|
@@ -97,7 +88,6 @@ module.exports = function (template, {
|
|
|
97
88
|
globalComponents: [],
|
|
98
89
|
// web模式下实现抽象组件
|
|
99
90
|
componentGenerics,
|
|
100
|
-
proxyComponentEvents,
|
|
101
91
|
hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules)
|
|
102
92
|
})
|
|
103
93
|
if (meta.wxsModuleMap) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.60",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=14.14.0"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "02a77bf602744c35703b2fdc27171edbec09edcb"
|
|
86
86
|
}
|