@mpxjs/webpack-plugin 2.9.0-beta.3 → 2.9.0-beta.4
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
|
@@ -124,7 +124,6 @@ class MpxWebpackPlugin {
|
|
|
124
124
|
options.resolveMode = options.resolveMode || 'webpack'
|
|
125
125
|
options.writeMode = options.writeMode || 'changed'
|
|
126
126
|
options.autoScopeRules = options.autoScopeRules || {}
|
|
127
|
-
options.renderOptimizeRules = options.renderOptimizeRules || {}
|
|
128
127
|
options.autoVirtualHostRules = options.autoVirtualHostRules || {}
|
|
129
128
|
options.forceDisableProxyCtor = options.forceDisableProxyCtor || false
|
|
130
129
|
options.transMpxRules = options.transMpxRules || {
|
|
@@ -168,16 +167,11 @@ class MpxWebpackPlugin {
|
|
|
168
167
|
}, options.nativeConfig)
|
|
169
168
|
options.webConfig = options.webConfig || {}
|
|
170
169
|
options.partialCompile = options.mode !== 'web' && options.partialCompile
|
|
171
|
-
options.asyncSubpackageRules = options.asyncSubpackageRules ||
|
|
170
|
+
options.asyncSubpackageRules = options.asyncSubpackageRules || []
|
|
171
|
+
options.optimizeRenderRules = options.optimizeRenderRules || {}
|
|
172
172
|
options.retryRequireAsync = options.retryRequireAsync || false
|
|
173
173
|
options.enableAliRequireAsync = options.enableAliRequireAsync || false
|
|
174
174
|
options.optimizeSize = options.optimizeSize || false
|
|
175
|
-
let proxyComponentEventsRules = []
|
|
176
|
-
const proxyComponentEventsRulesRaw = options.proxyComponentEventsRules
|
|
177
|
-
if (proxyComponentEventsRulesRaw) {
|
|
178
|
-
proxyComponentEventsRules = Array.isArray(proxyComponentEventsRulesRaw) ? proxyComponentEventsRulesRaw : [proxyComponentEventsRulesRaw]
|
|
179
|
-
}
|
|
180
|
-
options.proxyComponentEventsRules = proxyComponentEventsRules
|
|
181
175
|
this.options = options
|
|
182
176
|
// Hack for buildDependencies
|
|
183
177
|
const rawResolveBuildDependencies = FileSystemInfo.prototype.resolveBuildDependencies
|
|
@@ -638,7 +632,6 @@ class MpxWebpackPlugin {
|
|
|
638
632
|
appTitle: 'Mpx homepage',
|
|
639
633
|
attributes: this.options.attributes,
|
|
640
634
|
externals: this.options.externals,
|
|
641
|
-
renderOptimizeRules: this.options.renderOptimizeRules,
|
|
642
635
|
useRelativePath: this.options.useRelativePath,
|
|
643
636
|
removedChunks: [],
|
|
644
637
|
forceProxyEventRules: this.options.forceProxyEventRules,
|
|
@@ -657,7 +650,7 @@ class MpxWebpackPlugin {
|
|
|
657
650
|
})
|
|
658
651
|
},
|
|
659
652
|
asyncSubpackageRules: this.options.asyncSubpackageRules,
|
|
660
|
-
|
|
653
|
+
optimizeRenderRules: this.options.optimizeRenderRules,
|
|
661
654
|
pathHash: (resourcePath) => {
|
|
662
655
|
if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
|
|
663
656
|
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
|
|
|
@@ -1772,68 +1775,105 @@ function processBuiltInComponents (el, meta) {
|
|
|
1772
1775
|
}
|
|
1773
1776
|
}
|
|
1774
1777
|
|
|
1775
|
-
function
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1778
|
+
function processAliAddComponentRootView (el, options) {
|
|
1779
|
+
const processAttrsConditions = [
|
|
1780
|
+
{ condition: /^(on|catch)Tap$/, action: 'clone' },
|
|
1781
|
+
{ condition: /^(on|catch)TouchStart$/, action: 'clone' },
|
|
1782
|
+
{ condition: /^(on|catch)TouchMove$/, action: 'clone' },
|
|
1783
|
+
{ condition: /^(on|catch)TouchEnd$/, action: 'clone' },
|
|
1784
|
+
{ condition: /^(on|catch)TouchCancel$/, action: 'clone' },
|
|
1785
|
+
{ condition: /^(on|catch)LongTap$/, action: 'clone' },
|
|
1786
|
+
{ condition: /^data-/, action: 'clone' },
|
|
1787
|
+
{ condition: /^id$/, action: 'clone' },
|
|
1788
|
+
{ condition: /^style$/, action: 'move' },
|
|
1789
|
+
{ condition: /^slot$/, action: 'move' }
|
|
1790
|
+
]
|
|
1791
|
+
const processAppendAttrsRules = [
|
|
1792
|
+
{ name: 'class', value: `${MPX_ROOT_VIEW} host-${options.moduleId}` }
|
|
1793
|
+
]
|
|
1794
|
+
const newElAttrs = []
|
|
1795
|
+
const allAttrs = cloneAttrsList(el.attrsList)
|
|
1796
|
+
|
|
1797
|
+
function processClone (attr) {
|
|
1798
|
+
newElAttrs.push(attr)
|
|
1788
1799
|
}
|
|
1789
|
-
}
|
|
1790
1800
|
|
|
1791
|
-
function
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
const sep = name === 'style' ? ';' : ' '
|
|
1796
|
-
value = value ? `{{${typeName}||''}}${sep}${value}` : `{{${typeName}||''}}`
|
|
1797
|
-
return [name, value]
|
|
1798
|
-
}
|
|
1801
|
+
function processMove (attr) {
|
|
1802
|
+
getAndRemoveAttr(el, attr.name)
|
|
1803
|
+
newElAttrs.push(attr)
|
|
1804
|
+
}
|
|
1799
1805
|
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
const
|
|
1803
|
-
const
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1806
|
+
function processAppendRules (el) {
|
|
1807
|
+
processAppendAttrsRules.forEach((rule) => {
|
|
1808
|
+
const getNeedAppendAttrValue = el.attrsMap[rule.name]
|
|
1809
|
+
const value = getNeedAppendAttrValue ? getNeedAppendAttrValue + ' ' + rule.value : rule.value
|
|
1810
|
+
newElAttrs.push({
|
|
1811
|
+
name: rule.name,
|
|
1812
|
+
value
|
|
1807
1813
|
})
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1814
|
+
})
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
processAttrsConditions.forEach(item => {
|
|
1818
|
+
const matcher = normalizeCondition(item.condition)
|
|
1819
|
+
allAttrs.forEach((attr) => {
|
|
1820
|
+
if (matcher(attr.name)) {
|
|
1821
|
+
if (item.action === 'clone') {
|
|
1822
|
+
processClone(attr)
|
|
1823
|
+
} else if (item.action === 'move') {
|
|
1824
|
+
processMove(attr)
|
|
1825
|
+
}
|
|
1813
1826
|
}
|
|
1814
1827
|
})
|
|
1828
|
+
})
|
|
1829
|
+
|
|
1830
|
+
processAppendRules(el)
|
|
1831
|
+
const componentWrapView = createASTElement('view', newElAttrs)
|
|
1832
|
+
moveBaseDirective(componentWrapView, el)
|
|
1833
|
+
if (el.is && el.components) {
|
|
1834
|
+
el = postProcessComponentIs(el)
|
|
1815
1835
|
}
|
|
1836
|
+
|
|
1837
|
+
replaceNode(el, componentWrapView, true)
|
|
1838
|
+
addChild(componentWrapView, el)
|
|
1839
|
+
return componentWrapView
|
|
1816
1840
|
}
|
|
1817
1841
|
|
|
1818
1842
|
// 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
|
|
1819
1843
|
function getVirtualHostRoot (options, meta) {
|
|
1820
|
-
if (srcMode === 'wx'
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1844
|
+
if (srcMode === 'wx') {
|
|
1845
|
+
if (options.isComponent) {
|
|
1846
|
+
if ((mode === 'wx') && options.hasVirtualHost) {
|
|
1847
|
+
// wx组件注入virtualHost配置
|
|
1848
|
+
!meta.options && (meta.options = {})
|
|
1849
|
+
meta.options.virtualHost = true
|
|
1850
|
+
}
|
|
1851
|
+
if ((mode === 'web') && !options.hasVirtualHost) {
|
|
1852
|
+
// ali组件根节点实体化
|
|
1853
|
+
const rootView = createASTElement('view', [
|
|
1854
|
+
{
|
|
1855
|
+
name: 'class',
|
|
1856
|
+
value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
|
|
1857
|
+
},
|
|
1858
|
+
{
|
|
1859
|
+
name: 'v-on',
|
|
1860
|
+
value: '$listeners'
|
|
1861
|
+
}
|
|
1862
|
+
])
|
|
1863
|
+
rootView.hasEvent = true
|
|
1864
|
+
processElement(rootView, rootView, options, meta)
|
|
1865
|
+
return rootView
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
if (options.isPage) {
|
|
1869
|
+
if (mode === 'web') {
|
|
1870
|
+
return createASTElement('div', [
|
|
1871
|
+
{
|
|
1872
|
+
name: 'class',
|
|
1873
|
+
value: 'page'
|
|
1874
|
+
}
|
|
1875
|
+
])
|
|
1876
|
+
}
|
|
1837
1877
|
}
|
|
1838
1878
|
}
|
|
1839
1879
|
return getTempNode()
|
|
@@ -2013,16 +2053,6 @@ function processMpxTagName (el) {
|
|
|
2013
2053
|
}
|
|
2014
2054
|
|
|
2015
2055
|
function processElement (el, root, options, meta) {
|
|
2016
|
-
const transAli = mode === 'ali' && srcMode === 'wx'
|
|
2017
|
-
const transWeb = mode === 'web' && srcMode === 'wx'
|
|
2018
|
-
if (transAli) {
|
|
2019
|
-
processRootViewStyleClassHack(el, options, root)
|
|
2020
|
-
processRootViewEventHack(el, options, root)
|
|
2021
|
-
}
|
|
2022
|
-
if (transWeb) {
|
|
2023
|
-
processRootViewEventHack(el, options, root)
|
|
2024
|
-
}
|
|
2025
|
-
|
|
2026
2056
|
processAtMode(el)
|
|
2027
2057
|
// 如果已经标记了这个元素要被清除,直接return跳过后续处理步骤
|
|
2028
2058
|
if (el._atModeStatus === 'mismatch') {
|
|
@@ -2042,6 +2072,8 @@ function processElement (el, root, options, meta) {
|
|
|
2042
2072
|
|
|
2043
2073
|
processInjectWxs(el, meta)
|
|
2044
2074
|
|
|
2075
|
+
const transAli = mode === 'ali' && srcMode === 'wx'
|
|
2076
|
+
|
|
2045
2077
|
if (mode === 'web') {
|
|
2046
2078
|
// 收集内建组件
|
|
2047
2079
|
processBuiltInComponents(el, meta)
|
|
@@ -2093,7 +2125,11 @@ function closeElement (el, meta, options) {
|
|
|
2093
2125
|
postProcessWxs(el, meta)
|
|
2094
2126
|
|
|
2095
2127
|
if (!pass) {
|
|
2096
|
-
|
|
2128
|
+
if (isComponentNode(el, options) && !options.hasVirtualHost && mode === 'ali') {
|
|
2129
|
+
el = processAliAddComponentRootView(el, options)
|
|
2130
|
+
} else {
|
|
2131
|
+
el = postProcessComponentIs(el)
|
|
2132
|
+
}
|
|
2097
2133
|
}
|
|
2098
2134
|
postProcessFor(el)
|
|
2099
2135
|
postProcessIf(el)
|
|
@@ -2309,7 +2345,7 @@ function genFor (node) {
|
|
|
2309
2345
|
node.forProcessed = true
|
|
2310
2346
|
const index = node.for.index || 'index'
|
|
2311
2347
|
const item = node.for.item || 'item'
|
|
2312
|
-
return `
|
|
2348
|
+
return `_i(${node.for.exp}, function(${item},${index}){\n${genNode(node)}});\n`
|
|
2313
2349
|
}
|
|
2314
2350
|
|
|
2315
2351
|
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) {
|
|
@@ -24,7 +24,6 @@ module.exports = function (template, {
|
|
|
24
24
|
externalClasses,
|
|
25
25
|
checkUsingComponents,
|
|
26
26
|
webConfig,
|
|
27
|
-
proxyComponentEventsRules,
|
|
28
27
|
autoVirtualHostRules
|
|
29
28
|
} = mpx
|
|
30
29
|
const { resourcePath } = parseRequest(loaderContext.resource)
|
|
@@ -61,15 +60,6 @@ module.exports = function (template, {
|
|
|
61
60
|
if (template.content) {
|
|
62
61
|
const templateSrcMode = template.mode || srcMode
|
|
63
62
|
|
|
64
|
-
let proxyComponentEvents = null
|
|
65
|
-
for (const item of proxyComponentEventsRules) {
|
|
66
|
-
if (matchCondition(resourcePath, item)) {
|
|
67
|
-
const eventsRaw = item.events
|
|
68
|
-
proxyComponentEvents = Array.isArray(eventsRaw) ? eventsRaw : [eventsRaw]
|
|
69
|
-
break
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
63
|
const { root, meta } = templateCompiler.parse(template.content, {
|
|
74
64
|
warn: (msg) => {
|
|
75
65
|
loaderContext.emitWarning(
|
|
@@ -85,6 +75,7 @@ module.exports = function (template, {
|
|
|
85
75
|
hasComment,
|
|
86
76
|
isNative,
|
|
87
77
|
isComponent: ctorType === 'component',
|
|
78
|
+
isPage: ctorType === 'page',
|
|
88
79
|
mode,
|
|
89
80
|
srcMode: templateSrcMode,
|
|
90
81
|
defs,
|
|
@@ -100,7 +91,6 @@ module.exports = function (template, {
|
|
|
100
91
|
globalComponents: [],
|
|
101
92
|
// web模式下实现抽象组件
|
|
102
93
|
componentGenerics,
|
|
103
|
-
proxyComponentEvents,
|
|
104
94
|
hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules)
|
|
105
95
|
})
|
|
106
96
|
if (meta.wxsModuleMap) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.9.0-beta.
|
|
3
|
+
"version": "2.9.0-beta.4",
|
|
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": "300107cbcf0d6847e1d27896ea71ad4ce1387dd5"
|
|
86
86
|
}
|