@mpxjs/webpack-plugin 2.8.57 → 2.8.59
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
CHANGED
|
@@ -173,12 +173,6 @@ class MpxWebpackPlugin {
|
|
|
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
|
|
@@ -646,7 +640,6 @@ class MpxWebpackPlugin {
|
|
|
646
640
|
enableRequireAsync: this.options.mode === 'wx' || (this.options.mode === 'ali' && this.options.enableAliRequireAsync),
|
|
647
641
|
partialCompile: this.options.partialCompile,
|
|
648
642
|
asyncSubpackageRules: this.options.asyncSubpackageRules,
|
|
649
|
-
proxyComponentEventsRules: this.options.proxyComponentEventsRules,
|
|
650
643
|
pathHash: (resourcePath) => {
|
|
651
644
|
if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
|
|
652
645
|
return hash(path.relative(this.options.projectRoot, resourcePath))
|
|
@@ -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,9 +169,7 @@ function dealRemove (path, replace) {
|
|
|
163
169
|
t.validate(path, path.key, null)
|
|
164
170
|
path.remove()
|
|
165
171
|
}
|
|
166
|
-
} catch (e) {
|
|
167
|
-
console.error(e)
|
|
168
|
-
}
|
|
172
|
+
} catch (e) {}
|
|
169
173
|
}
|
|
170
174
|
|
|
171
175
|
module.exports = {
|
|
@@ -202,9 +206,23 @@ module.exports = {
|
|
|
202
206
|
Identifier (path) {
|
|
203
207
|
if (
|
|
204
208
|
checkBindThis(path) &&
|
|
205
|
-
!path.scope.hasBinding(path.node.name) &&
|
|
206
209
|
!ignoreMap[path.node.name]
|
|
207
210
|
) {
|
|
211
|
+
const scopeBinding = path.scope.hasBinding(path.node.name)
|
|
212
|
+
// 删除局部作用域的变量
|
|
213
|
+
if (scopeBinding) {
|
|
214
|
+
if (renderReduce) {
|
|
215
|
+
const { delPath, canDel, ignore, replace } = checkDelAndGetPath(path)
|
|
216
|
+
if (canDel && !ignore) {
|
|
217
|
+
delPath.delInfo = {
|
|
218
|
+
isLocal: true,
|
|
219
|
+
canDel,
|
|
220
|
+
replace
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return
|
|
225
|
+
}
|
|
208
226
|
const { last, keyPath } = calPropName(path)
|
|
209
227
|
path.needBind = true
|
|
210
228
|
if (needCollect) {
|
|
@@ -272,10 +290,14 @@ module.exports = {
|
|
|
272
290
|
enter (path) {
|
|
273
291
|
// 删除重复变量
|
|
274
292
|
if (path.delInfo) {
|
|
275
|
-
const { keyPath, canDel, replace } = path.delInfo
|
|
293
|
+
const { keyPath, canDel, isLocal, replace } = path.delInfo
|
|
276
294
|
delete path.delInfo
|
|
277
295
|
|
|
278
296
|
if (canDel) {
|
|
297
|
+
if (isLocal) { // 局部作用域里的变量,可直接删除
|
|
298
|
+
dealRemove(path, replace)
|
|
299
|
+
return
|
|
300
|
+
}
|
|
279
301
|
const data = bindingsMap.get(currentBlock)
|
|
280
302
|
const { bindings, pBindings } = data
|
|
281
303
|
const allBindings = Object.assign({}, pBindings, bindings)
|
|
@@ -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')
|
|
@@ -1750,68 +1751,105 @@ function processBuiltInComponents (el, meta) {
|
|
|
1750
1751
|
}
|
|
1751
1752
|
}
|
|
1752
1753
|
|
|
1753
|
-
function
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1754
|
+
function processAliAddComponentRootView (el, options) {
|
|
1755
|
+
const processAttrsConditions = [
|
|
1756
|
+
{ condition: /^(on|catch)Tap$/, action: 'clone' },
|
|
1757
|
+
{ condition: /^(on|catch)TouchStart$/, action: 'clone' },
|
|
1758
|
+
{ condition: /^(on|catch)TouchMove$/, action: 'clone' },
|
|
1759
|
+
{ condition: /^(on|catch)TouchEnd$/, action: 'clone' },
|
|
1760
|
+
{ condition: /^(on|catch)TouchCancel$/, action: 'clone' },
|
|
1761
|
+
{ condition: /^(on|catch)LongTap$/, action: 'clone' },
|
|
1762
|
+
{ condition: /^data-/, action: 'clone' },
|
|
1763
|
+
{ condition: /^id$/, action: 'clone' },
|
|
1764
|
+
{ condition: /^style$/, action: 'move' },
|
|
1765
|
+
{ condition: /^slot$/, action: 'move' }
|
|
1766
|
+
]
|
|
1767
|
+
const processAppendAttrsRules = [
|
|
1768
|
+
{ name: 'class', value: `${MPX_ROOT_VIEW} host-${options.moduleId}` }
|
|
1769
|
+
]
|
|
1770
|
+
const newElAttrs = []
|
|
1771
|
+
const allAttrs = cloneAttrsList(el.attrsList)
|
|
1772
|
+
|
|
1773
|
+
function processClone (attr) {
|
|
1774
|
+
newElAttrs.push(attr)
|
|
1766
1775
|
}
|
|
1767
|
-
}
|
|
1768
1776
|
|
|
1769
|
-
function
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
const sep = name === 'style' ? ';' : ' '
|
|
1774
|
-
value = value ? `{{${typeName}||''}}${sep}${value}` : `{{${typeName}||''}}`
|
|
1775
|
-
return [name, value]
|
|
1776
|
-
}
|
|
1777
|
+
function processMove (attr) {
|
|
1778
|
+
getAndRemoveAttr(el, attr.name)
|
|
1779
|
+
newElAttrs.push(attr)
|
|
1780
|
+
}
|
|
1777
1781
|
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
const
|
|
1781
|
-
const
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1782
|
+
function processAppendRules (el) {
|
|
1783
|
+
processAppendAttrsRules.forEach((rule) => {
|
|
1784
|
+
const getNeedAppendAttrValue = el.attrsMap[rule.name]
|
|
1785
|
+
const value = getNeedAppendAttrValue ? getNeedAppendAttrValue + ' ' + rule.value : rule.value
|
|
1786
|
+
newElAttrs.push({
|
|
1787
|
+
name: rule.name,
|
|
1788
|
+
value
|
|
1785
1789
|
})
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1790
|
+
})
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
processAttrsConditions.forEach(item => {
|
|
1794
|
+
const matcher = normalizeCondition(item.condition)
|
|
1795
|
+
allAttrs.forEach((attr) => {
|
|
1796
|
+
if (matcher(attr.name)) {
|
|
1797
|
+
if (item.action === 'clone') {
|
|
1798
|
+
processClone(attr)
|
|
1799
|
+
} else if (item.action === 'move') {
|
|
1800
|
+
processMove(attr)
|
|
1801
|
+
}
|
|
1791
1802
|
}
|
|
1792
1803
|
})
|
|
1804
|
+
})
|
|
1805
|
+
|
|
1806
|
+
processAppendRules(el)
|
|
1807
|
+
const componentWrapView = createASTElement('view', newElAttrs)
|
|
1808
|
+
moveBaseDirective(componentWrapView, el)
|
|
1809
|
+
if (el.is && el.components) {
|
|
1810
|
+
el = postProcessComponentIs(el)
|
|
1793
1811
|
}
|
|
1812
|
+
|
|
1813
|
+
replaceNode(el, componentWrapView, true)
|
|
1814
|
+
addChild(componentWrapView, el)
|
|
1815
|
+
return componentWrapView
|
|
1794
1816
|
}
|
|
1795
1817
|
|
|
1796
1818
|
// 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
|
|
1797
1819
|
function getVirtualHostRoot (options, meta) {
|
|
1798
|
-
if (srcMode === 'wx'
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1820
|
+
if (srcMode === 'wx') {
|
|
1821
|
+
if (options.isComponent) {
|
|
1822
|
+
if ((mode === 'wx') && options.hasVirtualHost) {
|
|
1823
|
+
// wx组件注入virtualHost配置
|
|
1824
|
+
!meta.options && (meta.options = {})
|
|
1825
|
+
meta.options.virtualHost = true
|
|
1826
|
+
}
|
|
1827
|
+
if ((mode === 'web') && !options.hasVirtualHost) {
|
|
1828
|
+
// ali组件根节点实体化
|
|
1829
|
+
const rootView = createASTElement('view', [
|
|
1830
|
+
{
|
|
1831
|
+
name: 'class',
|
|
1832
|
+
value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
|
|
1833
|
+
},
|
|
1834
|
+
{
|
|
1835
|
+
name: 'v-on',
|
|
1836
|
+
value: '$listeners'
|
|
1837
|
+
}
|
|
1838
|
+
])
|
|
1839
|
+
rootView.hasEvent = true
|
|
1840
|
+
processElement(rootView, rootView, options, meta)
|
|
1841
|
+
return rootView
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
if (options.isPage) {
|
|
1845
|
+
if (mode === 'web') {
|
|
1846
|
+
return createASTElement('div', [
|
|
1847
|
+
{
|
|
1848
|
+
name: 'class',
|
|
1849
|
+
value: 'page'
|
|
1850
|
+
}
|
|
1851
|
+
])
|
|
1852
|
+
}
|
|
1815
1853
|
}
|
|
1816
1854
|
}
|
|
1817
1855
|
return getTempNode()
|
|
@@ -1991,16 +2029,6 @@ function processMpxTagName (el) {
|
|
|
1991
2029
|
}
|
|
1992
2030
|
|
|
1993
2031
|
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
2032
|
processAtMode(el)
|
|
2005
2033
|
// 如果已经标记了这个元素要被清除,直接return跳过后续处理步骤
|
|
2006
2034
|
if (el._atModeStatus === 'mismatch') {
|
|
@@ -2020,6 +2048,8 @@ function processElement (el, root, options, meta) {
|
|
|
2020
2048
|
|
|
2021
2049
|
processInjectWxs(el, meta)
|
|
2022
2050
|
|
|
2051
|
+
const transAli = mode === 'ali' && srcMode === 'wx'
|
|
2052
|
+
|
|
2023
2053
|
if (mode === 'web') {
|
|
2024
2054
|
// 收集内建组件
|
|
2025
2055
|
processBuiltInComponents(el, meta)
|
|
@@ -2071,7 +2101,11 @@ function closeElement (el, meta, options) {
|
|
|
2071
2101
|
postProcessWxs(el, meta)
|
|
2072
2102
|
|
|
2073
2103
|
if (!pass) {
|
|
2074
|
-
|
|
2104
|
+
if (isComponentNode(el, options) && !options.hasVirtualHost && mode === 'ali') {
|
|
2105
|
+
el = processAliAddComponentRootView(el, options)
|
|
2106
|
+
} else {
|
|
2107
|
+
el = postProcessComponentIs(el)
|
|
2108
|
+
}
|
|
2075
2109
|
}
|
|
2076
2110
|
postProcessFor(el)
|
|
2077
2111
|
postProcessIf(el)
|
|
@@ -19,6 +19,7 @@ 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
24
|
const renderOptimizeRules = mpx.renderOptimizeRules
|
|
24
25
|
const usingComponents = queryObj.usingComponents || []
|
|
@@ -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) {
|
|
@@ -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.59",
|
|
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": "4e014ea355bb2d659c6fd6a3040b6b88245da9e5"
|
|
86
86
|
}
|