@mpxjs/webpack-plugin 2.8.51 → 2.8.54
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.
|
@@ -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
|
|
@@ -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>
|
|
@@ -1795,7 +1795,7 @@ function processRootViewStyleClassHack (el, options, root) {
|
|
|
1795
1795
|
|
|
1796
1796
|
// 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
|
|
1797
1797
|
function getVirtualHostRoot (options, meta) {
|
|
1798
|
-
if (options.isComponent) {
|
|
1798
|
+
if (srcMode === 'wx' && options.isComponent) {
|
|
1799
1799
|
// 处理组件时
|
|
1800
1800
|
if (mode === 'wx' && options.hasVirtualHost) {
|
|
1801
1801
|
// wx组件注入virtualHost配置
|
|
@@ -1810,7 +1810,6 @@ function getVirtualHostRoot (options, meta) {
|
|
|
1810
1810
|
value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
|
|
1811
1811
|
}
|
|
1812
1812
|
])
|
|
1813
|
-
// 添加时间处理
|
|
1814
1813
|
processElement(rootView, rootView, options, meta)
|
|
1815
1814
|
return rootView
|
|
1816
1815
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.54",
|
|
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": "e39ad9b35cdb336f271f424dbfae9cf7688c8d0d"
|
|
85
85
|
}
|