@mpxjs/webpack-plugin 2.8.50 → 2.8.53
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 +7 -0
- package/lib/json-compiler/index.js +3 -0
- package/lib/loader.js +1 -1
- package/lib/native-loader.js +1 -1
- package/lib/runtime/components/web/mpx-scroll-view.vue +10 -2
- package/lib/runtime/components/web/mpx-web-view.vue +74 -34
- package/lib/style-compiler/index.js +4 -0
- package/lib/template-compiler/compiler.js +57 -73
- package/lib/template-compiler/index.js +14 -1
- package/lib/web/processScript.js +4 -2
- package/lib/web/processTemplate.js +17 -34
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -173,6 +173,12 @@ 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
|
|
176
182
|
this.options = options
|
|
177
183
|
// Hack for buildDependencies
|
|
178
184
|
const rawResolveBuildDependencies = FileSystemInfo.prototype.resolveBuildDependencies
|
|
@@ -640,6 +646,7 @@ class MpxWebpackPlugin {
|
|
|
640
646
|
enableRequireAsync: this.options.mode === 'wx' || (this.options.mode === 'ali' && this.options.enableAliRequireAsync),
|
|
641
647
|
partialCompile: this.options.partialCompile,
|
|
642
648
|
asyncSubpackageRules: this.options.asyncSubpackageRules,
|
|
649
|
+
proxyComponentEventsRules: this.options.proxyComponentEventsRules,
|
|
643
650
|
pathHash: (resourcePath) => {
|
|
644
651
|
if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
|
|
645
652
|
return hash(path.relative(this.options.projectRoot, resourcePath))
|
|
@@ -154,6 +154,9 @@ module.exports = function (content) {
|
|
|
154
154
|
if (!json.usingComponents) {
|
|
155
155
|
json.usingComponents = {}
|
|
156
156
|
}
|
|
157
|
+
if (!json.component && mode === 'swan') {
|
|
158
|
+
json.component = true
|
|
159
|
+
}
|
|
157
160
|
}
|
|
158
161
|
} else if (componentsMap[resourcePath]) {
|
|
159
162
|
// component
|
package/lib/loader.js
CHANGED
|
@@ -280,7 +280,7 @@ module.exports = function (content) {
|
|
|
280
280
|
let ctor = 'App'
|
|
281
281
|
if (ctorType === 'page') {
|
|
282
282
|
// swan也默认使用Page构造器
|
|
283
|
-
if (mpx.forceUsePageCtor || mode === 'ali'
|
|
283
|
+
if (mpx.forceUsePageCtor || mode === 'ali') {
|
|
284
284
|
ctor = 'Page'
|
|
285
285
|
} else {
|
|
286
286
|
ctor = 'Component'
|
package/lib/native-loader.js
CHANGED
|
@@ -214,7 +214,7 @@ module.exports = function (content) {
|
|
|
214
214
|
let ctorType = 'app'
|
|
215
215
|
if (pagesMap[resourcePath]) {
|
|
216
216
|
ctorType = 'page'
|
|
217
|
-
if (mpx.forceUsePageCtor || mode === 'ali'
|
|
217
|
+
if (mpx.forceUsePageCtor || mode === 'ali') {
|
|
218
218
|
ctor = 'Page'
|
|
219
219
|
} else {
|
|
220
220
|
ctor = 'Component'
|
|
@@ -345,7 +345,11 @@
|
|
|
345
345
|
class: 'circle circle-c'
|
|
346
346
|
}),
|
|
347
347
|
]
|
|
348
|
-
) :
|
|
348
|
+
) : this.$slots.refresher
|
|
349
|
+
? createElement('div', {
|
|
350
|
+
class: 'mpx-pull-down-slot',
|
|
351
|
+
}, this.$slots.refresher)
|
|
352
|
+
: null
|
|
349
353
|
|
|
350
354
|
const pullDownWrapper = this.refresherEnabled ? createElement('div', {
|
|
351
355
|
class: 'mpx-pull-down-wrapper',
|
|
@@ -379,7 +383,11 @@
|
|
|
379
383
|
bottom: 20px
|
|
380
384
|
left: 50%
|
|
381
385
|
transform: translateX(-50%)
|
|
382
|
-
|
|
386
|
+
.mpx-pull-down-slot
|
|
387
|
+
position: absolute
|
|
388
|
+
width: 100%
|
|
389
|
+
height: auto
|
|
390
|
+
bottom: 0
|
|
383
391
|
.mpx-pull-down-content-black
|
|
384
392
|
.circle
|
|
385
393
|
display: inline-block;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<iframe ref="mpxIframe" class="mpx-iframe" :src="
|
|
2
|
+
<iframe ref="mpxIframe" class="mpx-iframe" :src="currentUrl"></iframe>
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
5
|
<script>
|
|
6
6
|
import { getCustomEvent } from './getInnerListeners'
|
|
7
|
-
import { redirectTo, navigateTo, navigateBack, reLaunch, switchTab} from '@mpxjs/api-proxy/src/web/api/index'
|
|
7
|
+
import { redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy/src/web/api/index'
|
|
8
8
|
|
|
9
9
|
const eventLoad = 'load'
|
|
10
10
|
const eventError = 'error'
|
|
11
11
|
const eventMessage = 'message'
|
|
12
|
+
const mpx = global.__mpx
|
|
12
13
|
export default {
|
|
13
14
|
data: function () {
|
|
14
15
|
return {
|
|
@@ -17,7 +18,8 @@
|
|
|
17
18
|
Loaded: false,
|
|
18
19
|
isActived: false,
|
|
19
20
|
mpxIframe: null,
|
|
20
|
-
isPostMessage: false
|
|
21
|
+
isPostMessage: false,
|
|
22
|
+
currentUrl: ''
|
|
21
23
|
}
|
|
22
24
|
},
|
|
23
25
|
props: {
|
|
@@ -25,22 +27,29 @@
|
|
|
25
27
|
type: String
|
|
26
28
|
}
|
|
27
29
|
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
domain = src.substr(0, index)
|
|
35
|
-
return domain
|
|
36
|
-
}
|
|
37
|
-
domain = src.split('/')
|
|
38
|
-
if (domain[2]) {
|
|
39
|
-
domain = domain[0] + '//' + domain[2]
|
|
30
|
+
watch: {
|
|
31
|
+
src (value) {
|
|
32
|
+
let host
|
|
33
|
+
host = value.split('/')
|
|
34
|
+
if (host[2]) {
|
|
35
|
+
host = host[0] + '//' + host[2]
|
|
40
36
|
} else {
|
|
41
|
-
|
|
37
|
+
host = ''
|
|
38
|
+
}
|
|
39
|
+
const hostValidate = this.hostValidate(host)
|
|
40
|
+
if (!hostValidate) {
|
|
41
|
+
console.error('访问页面域名不符合domainWhiteLists白名单配置,请确认是否正确配置该域名白名单')
|
|
42
|
+
return
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
+
this.currentUrl = value
|
|
45
|
+
this.mpxIframe = this.$refs.mpxIframe
|
|
46
|
+
this.mpxIframe.addEventListener('load', (event) => {
|
|
47
|
+
this.Loaded = true
|
|
48
|
+
const loadData = {
|
|
49
|
+
src: this.src
|
|
50
|
+
}
|
|
51
|
+
this.$emit(eventLoad, getCustomEvent(eventLoad, loadData, this))
|
|
52
|
+
})
|
|
44
53
|
}
|
|
45
54
|
},
|
|
46
55
|
mounted () {
|
|
@@ -52,48 +61,67 @@
|
|
|
52
61
|
this.$emit(eventError, getCustomEvent(eventError, loadData, this))
|
|
53
62
|
}
|
|
54
63
|
}, 1000)
|
|
55
|
-
this.mpxIframe = this.$refs.mpxIframe
|
|
56
|
-
this.mpxIframe.addEventListener('load', (event) => {
|
|
57
|
-
event.currentTarget.contentWindow.postMessage(this.mainDomain, '*')
|
|
58
|
-
})
|
|
59
64
|
window.addEventListener('message', (event) => {
|
|
65
|
+
const hostValidate = this.hostValidate(event.origin)
|
|
66
|
+
const hasPostMessage = this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage
|
|
60
67
|
const data = event.data
|
|
61
|
-
const value = data.
|
|
62
|
-
if (!this.isActived) {
|
|
68
|
+
const value = data.payload
|
|
69
|
+
if (!this.isActived || !hostValidate) {
|
|
63
70
|
return
|
|
64
71
|
}
|
|
72
|
+
let asyncCallback = null
|
|
65
73
|
switch (data.type) {
|
|
66
|
-
case
|
|
74
|
+
case 'postMessage':
|
|
67
75
|
this.isPostMessage = true
|
|
68
76
|
this.messageList.push(value.data)
|
|
77
|
+
asyncCallback = Promise.resolve({
|
|
78
|
+
errMsg: 'invokeWebappApi:ok'
|
|
79
|
+
})
|
|
69
80
|
break
|
|
70
81
|
case 'navigateTo':
|
|
71
82
|
this.isActived = false
|
|
72
|
-
navigateTo(value)
|
|
83
|
+
asyncCallback = navigateTo(value)
|
|
73
84
|
break
|
|
74
85
|
case 'navigateBack':
|
|
75
86
|
this.isActived = false
|
|
76
|
-
value ? navigateBack(value) : navigateBack()
|
|
87
|
+
asyncCallback = value ? navigateBack(value) : navigateBack()
|
|
77
88
|
break
|
|
78
89
|
case 'redirectTo':
|
|
79
90
|
this.isActived = false
|
|
80
|
-
redirectTo(value)
|
|
91
|
+
asyncCallback = redirectTo(value)
|
|
81
92
|
break
|
|
82
93
|
case 'switchTab':
|
|
83
94
|
this.isActived = false
|
|
84
|
-
switchTab(value)
|
|
95
|
+
asyncCallback = switchTab(value)
|
|
85
96
|
break
|
|
86
97
|
case 'reLaunch':
|
|
87
98
|
this.isActived = false
|
|
88
|
-
reLaunch(value)
|
|
99
|
+
asyncCallback = reLaunch(value)
|
|
89
100
|
break
|
|
90
|
-
case '
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
101
|
+
case 'getLocation':
|
|
102
|
+
const getLocation = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations.getLocation
|
|
103
|
+
if (getLocation) {
|
|
104
|
+
asyncCallback = getLocation()
|
|
105
|
+
} else {
|
|
106
|
+
asyncCallback = Promise.reject({
|
|
107
|
+
errMsg: '未在apiImplementations中配置getLocation方法'
|
|
108
|
+
})
|
|
94
109
|
}
|
|
95
|
-
|
|
110
|
+
break
|
|
96
111
|
}
|
|
112
|
+
asyncCallback && asyncCallback.then((res) => {
|
|
113
|
+
hasPostMessage && this.mpxIframe.contentWindow.postMessage({
|
|
114
|
+
type: data.type,
|
|
115
|
+
callbackId: data.callbackId,
|
|
116
|
+
result: res
|
|
117
|
+
}, event.origin)
|
|
118
|
+
}).catch((error) => {
|
|
119
|
+
hasPostMessage && this.mpxIframe.contentWindow.postMessage({
|
|
120
|
+
type: data.type,
|
|
121
|
+
callbackId: data.callbackId,
|
|
122
|
+
error
|
|
123
|
+
}, event.origin)
|
|
124
|
+
})
|
|
97
125
|
})
|
|
98
126
|
},
|
|
99
127
|
activated () {
|
|
@@ -119,6 +147,18 @@
|
|
|
119
147
|
data: this.messageList
|
|
120
148
|
}
|
|
121
149
|
this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
|
|
150
|
+
},
|
|
151
|
+
methods: {
|
|
152
|
+
hostValidate (host) {
|
|
153
|
+
const hostWhitelists = mpx.config.webviewConfig && mpx.config.webviewConfig.hostWhitelists || []
|
|
154
|
+
if (hostWhitelists.length) {
|
|
155
|
+
return hostWhitelists.some((item) => {
|
|
156
|
+
return host.endsWith(item)
|
|
157
|
+
})
|
|
158
|
+
} else {
|
|
159
|
+
return true
|
|
160
|
+
}
|
|
161
|
+
}
|
|
122
162
|
}
|
|
123
163
|
}
|
|
124
164
|
</script>
|
|
@@ -3,7 +3,6 @@ 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')
|
|
7
6
|
const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
|
|
8
7
|
const isEmptyObject = require('../utils/is-empty-object')
|
|
9
8
|
const getRulesRunner = require('../platform/index')
|
|
@@ -1751,67 +1750,47 @@ function processBuiltInComponents (el, meta) {
|
|
|
1751
1750
|
}
|
|
1752
1751
|
}
|
|
1753
1752
|
|
|
1754
|
-
function
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
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: /^style$/, action: 'move' },
|
|
1764
|
-
{ condition: /^slot$/, action: 'move' }
|
|
1765
|
-
]
|
|
1766
|
-
const processAppendAttrsRules = [
|
|
1767
|
-
{ name: 'class', value: `${MPX_ROOT_VIEW} host-${options.moduleId}` }
|
|
1768
|
-
]
|
|
1769
|
-
const newElAttrs = []
|
|
1770
|
-
const allAttrs = cloneAttrsList(el.attrsList)
|
|
1771
|
-
|
|
1772
|
-
function processClone (attr) {
|
|
1773
|
-
newElAttrs.push(attr)
|
|
1774
|
-
}
|
|
1775
|
-
|
|
1776
|
-
function processMove (attr) {
|
|
1777
|
-
getAndRemoveAttr(el, attr.name)
|
|
1778
|
-
newElAttrs.push(attr)
|
|
1753
|
+
function processRootViewEventHack (el, options, root) {
|
|
1754
|
+
// 只处理组件根节点
|
|
1755
|
+
if (!(options.isComponent && el === root && isRealNode(el))) {
|
|
1756
|
+
return
|
|
1779
1757
|
}
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
value
|
|
1788
|
-
})
|
|
1758
|
+
const { proxyComponentEvents } = options
|
|
1759
|
+
if (proxyComponentEvents) {
|
|
1760
|
+
proxyComponentEvents.forEach((type) => {
|
|
1761
|
+
addAttrs(el, [{
|
|
1762
|
+
name: type,
|
|
1763
|
+
value: '__proxyEvent'
|
|
1764
|
+
}])
|
|
1789
1765
|
})
|
|
1790
1766
|
}
|
|
1767
|
+
}
|
|
1791
1768
|
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1769
|
+
function processRootViewStyleClassHack (el, options, root) {
|
|
1770
|
+
// 处理组件根节点
|
|
1771
|
+
if (options.isComponent && el === root && isRealNode(el)) {
|
|
1772
|
+
const processor = ({ name, value, typeName }) => {
|
|
1773
|
+
const sep = name === 'style' ? ';' : ' '
|
|
1774
|
+
value = value ? `{{${typeName}||''}}${sep}${value}` : `{{${typeName}||''}}`
|
|
1775
|
+
return [name, value]
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
['style', 'class'].forEach((type) => {
|
|
1779
|
+
const exp = getAndRemoveAttr(el, type).val
|
|
1780
|
+
const typeName = type === 'class' ? 'className' : type
|
|
1781
|
+
const [newName, newValue] = processor({
|
|
1782
|
+
name: type,
|
|
1783
|
+
value: exp,
|
|
1784
|
+
typeName
|
|
1785
|
+
})
|
|
1786
|
+
if (newValue !== undefined) {
|
|
1787
|
+
addAttrs(el, [{
|
|
1788
|
+
name: newName,
|
|
1789
|
+
value: newValue
|
|
1790
|
+
}])
|
|
1801
1791
|
}
|
|
1802
1792
|
})
|
|
1803
|
-
})
|
|
1804
|
-
|
|
1805
|
-
processAppendRules(el)
|
|
1806
|
-
const componentWrapView = createASTElement('view', newElAttrs)
|
|
1807
|
-
moveBaseDirective(componentWrapView, el)
|
|
1808
|
-
if (el.is && el.components) {
|
|
1809
|
-
el = postProcessComponentIs(el)
|
|
1810
1793
|
}
|
|
1811
|
-
|
|
1812
|
-
replaceNode(el, componentWrapView, true)
|
|
1813
|
-
addChild(componentWrapView, el)
|
|
1814
|
-
return componentWrapView
|
|
1815
1794
|
}
|
|
1816
1795
|
|
|
1817
1796
|
// 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
|
|
@@ -1823,17 +1802,18 @@ function getVirtualHostRoot (options, meta) {
|
|
|
1823
1802
|
!meta.options && (meta.options = {})
|
|
1824
1803
|
meta.options.virtualHost = true
|
|
1825
1804
|
}
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1805
|
+
if ((mode === 'ali' || mode === 'web') && !options.hasVirtualHost) {
|
|
1806
|
+
// ali组件根节点实体化
|
|
1807
|
+
const rootView = createASTElement('view', [
|
|
1808
|
+
{
|
|
1809
|
+
name: 'class',
|
|
1810
|
+
value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
|
|
1811
|
+
}
|
|
1812
|
+
])
|
|
1813
|
+
// 添加时间处理
|
|
1814
|
+
processElement(rootView, rootView, options, meta)
|
|
1815
|
+
return rootView
|
|
1816
|
+
}
|
|
1837
1817
|
}
|
|
1838
1818
|
return getTempNode()
|
|
1839
1819
|
}
|
|
@@ -2012,6 +1992,16 @@ function processMpxTagName (el) {
|
|
|
2012
1992
|
}
|
|
2013
1993
|
|
|
2014
1994
|
function processElement (el, root, options, meta) {
|
|
1995
|
+
const transAli = mode === 'ali' && srcMode === 'wx'
|
|
1996
|
+
const transWeb = mode === 'web' && srcMode === 'wx'
|
|
1997
|
+
if (transAli) {
|
|
1998
|
+
processRootViewStyleClassHack(el, options, root)
|
|
1999
|
+
processRootViewEventHack(el, options, root)
|
|
2000
|
+
}
|
|
2001
|
+
if (transWeb) {
|
|
2002
|
+
processRootViewEventHack(el, options, root)
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2015
2005
|
processAtMode(el)
|
|
2016
2006
|
// 如果已经标记了这个元素要被清除,直接return跳过后续处理步骤
|
|
2017
2007
|
if (el._atModeStatus === 'mismatch') {
|
|
@@ -2031,8 +2021,6 @@ function processElement (el, root, options, meta) {
|
|
|
2031
2021
|
|
|
2032
2022
|
processInjectWxs(el, meta)
|
|
2033
2023
|
|
|
2034
|
-
const transAli = mode === 'ali' && srcMode === 'wx'
|
|
2035
|
-
|
|
2036
2024
|
if (mode === 'web') {
|
|
2037
2025
|
// 收集内建组件
|
|
2038
2026
|
processBuiltInComponents(el, meta)
|
|
@@ -2084,11 +2072,7 @@ function closeElement (el, meta, options) {
|
|
|
2084
2072
|
postProcessWxs(el, meta)
|
|
2085
2073
|
|
|
2086
2074
|
if (!pass) {
|
|
2087
|
-
|
|
2088
|
-
el = processAliAddComponentRootView(el, options)
|
|
2089
|
-
} else {
|
|
2090
|
-
el = postProcessComponentIs(el)
|
|
2091
|
-
}
|
|
2075
|
+
el = postProcessComponentIs(el)
|
|
2092
2076
|
}
|
|
2093
2077
|
postProcessFor(el)
|
|
2094
2078
|
postProcessIf(el)
|
|
@@ -40,6 +40,14 @@ module.exports = function (raw) {
|
|
|
40
40
|
)
|
|
41
41
|
}
|
|
42
42
|
|
|
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
|
+
}
|
|
43
51
|
const { root: ast, meta } = compiler.parse(raw, {
|
|
44
52
|
warn,
|
|
45
53
|
error,
|
|
@@ -62,7 +70,8 @@ module.exports = function (raw) {
|
|
|
62
70
|
checkUsingComponents: matchCondition(resourcePath, mpx.checkUsingComponentsRules),
|
|
63
71
|
globalComponents: Object.keys(mpx.usingComponents),
|
|
64
72
|
forceProxyEvent: matchCondition(resourcePath, mpx.forceProxyEventRules),
|
|
65
|
-
hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules)
|
|
73
|
+
hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules),
|
|
74
|
+
proxyComponentEvents
|
|
66
75
|
})
|
|
67
76
|
|
|
68
77
|
if (meta.wxsContentMap) {
|
|
@@ -133,6 +142,10 @@ global.currentInject.getRefsData = function () {
|
|
|
133
142
|
};\n`
|
|
134
143
|
}
|
|
135
144
|
|
|
145
|
+
if (meta.options) {
|
|
146
|
+
resultSource += `global.currentInject.injectOptions = ${JSON.stringify(meta.options)};` + '\n'
|
|
147
|
+
}
|
|
148
|
+
|
|
136
149
|
this.emitFile(resourcePath, '', undefined, {
|
|
137
150
|
skipEmit: true,
|
|
138
151
|
extractedResultSource: resultSource
|
package/lib/web/processScript.js
CHANGED
|
@@ -182,8 +182,10 @@ module.exports = function (script, {
|
|
|
182
182
|
pagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
if (pagePath === jsonConfig.entryPagePath) {
|
|
186
|
+
firstPage = pagePath
|
|
187
|
+
}
|
|
188
|
+
if (!firstPage && pageCfg.isFirst) {
|
|
187
189
|
firstPage = pagePath
|
|
188
190
|
}
|
|
189
191
|
})
|
|
@@ -2,23 +2,7 @@ const templateCompiler = require('../template-compiler/compiler')
|
|
|
2
2
|
const genComponentTag = require('../utils/gen-component-tag')
|
|
3
3
|
const addQuery = require('../utils/add-query')
|
|
4
4
|
const parseRequest = require('../utils/parse-request')
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function calculateRootEleChild (arr) {
|
|
8
|
-
if (!arr) {
|
|
9
|
-
return 0
|
|
10
|
-
}
|
|
11
|
-
return arr.reduce((total, item) => {
|
|
12
|
-
if (item.type === 1) {
|
|
13
|
-
if (item.tag === 'template') {
|
|
14
|
-
total += calculateRootEleChild(item.children)
|
|
15
|
-
} else {
|
|
16
|
-
total += 1
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return total
|
|
20
|
-
}, 0)
|
|
21
|
-
}
|
|
5
|
+
const { matchCondition } = require('../utils/match-condition')
|
|
22
6
|
|
|
23
7
|
module.exports = function (template, {
|
|
24
8
|
loaderContext,
|
|
@@ -38,8 +22,9 @@ module.exports = function (template, {
|
|
|
38
22
|
wxsContentMap,
|
|
39
23
|
decodeHTMLText,
|
|
40
24
|
externalClasses,
|
|
41
|
-
checkUsingComponents
|
|
42
|
-
|
|
25
|
+
checkUsingComponents,
|
|
26
|
+
proxyComponentEventsRules,
|
|
27
|
+
autoVirtualHostRules
|
|
43
28
|
} = mpx
|
|
44
29
|
const { resourcePath } = parseRequest(loaderContext.resource)
|
|
45
30
|
const builtInComponentsMap = {}
|
|
@@ -72,6 +57,16 @@ module.exports = function (template, {
|
|
|
72
57
|
}
|
|
73
58
|
if (template.content) {
|
|
74
59
|
const templateSrcMode = template.mode || srcMode
|
|
60
|
+
|
|
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
|
+
|
|
75
70
|
const { root, meta } = templateCompiler.parse(template.content, {
|
|
76
71
|
warn: (msg) => {
|
|
77
72
|
loaderContext.emitWarning(
|
|
@@ -101,9 +96,9 @@ module.exports = function (template, {
|
|
|
101
96
|
// web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
|
|
102
97
|
globalComponents: [],
|
|
103
98
|
// web模式下实现抽象组件
|
|
104
|
-
componentGenerics
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
componentGenerics,
|
|
100
|
+
proxyComponentEvents,
|
|
101
|
+
hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules)
|
|
107
102
|
})
|
|
108
103
|
if (meta.wxsModuleMap) {
|
|
109
104
|
wxsModuleMap = meta.wxsModuleMap
|
|
@@ -123,18 +118,6 @@ module.exports = function (template, {
|
|
|
123
118
|
if (meta.genericsInfo) {
|
|
124
119
|
genericsInfo = meta.genericsInfo
|
|
125
120
|
}
|
|
126
|
-
// 输出H5有多个root element时, 使用mpx-root-view标签包裹
|
|
127
|
-
// todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
|
|
128
|
-
if (root.tag === 'temp-node') {
|
|
129
|
-
const childLen = calculateRootEleChild(root.children)
|
|
130
|
-
if (childLen >= 2) {
|
|
131
|
-
root.tag = 'div'
|
|
132
|
-
templateCompiler.addAttrs(root, [{
|
|
133
|
-
name: 'class',
|
|
134
|
-
value: 'mpx-root-view'
|
|
135
|
-
}])
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
121
|
return templateCompiler.serialize(root)
|
|
139
122
|
}
|
|
140
123
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.53",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"engines": {
|
|
82
82
|
"node": ">=14.14.0"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "cad6b8f0d2b1c8e520bfafa1de3bbf332466d801"
|
|
85
85
|
}
|