@mpxjs/webpack-plugin 2.9.69 → 2.9.70-alpha.0

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.
Files changed (138) hide show
  1. package/README.md +1 -1
  2. package/lib/config.js +14 -0
  3. package/lib/dependencies/AddEntryDependency.js +24 -0
  4. package/lib/dependencies/ResolveDependency.js +5 -0
  5. package/lib/index.js +38 -7
  6. package/lib/json-compiler/helper.js +3 -3
  7. package/lib/loader.js +53 -0
  8. package/lib/platform/template/wx/component-config/button.js +14 -2
  9. package/lib/platform/template/wx/component-config/image.js +4 -0
  10. package/lib/platform/template/wx/component-config/input.js +5 -1
  11. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  12. package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
  13. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  14. package/lib/platform/template/wx/component-config/switch.js +4 -0
  15. package/lib/platform/template/wx/component-config/text.js +4 -0
  16. package/lib/platform/template/wx/component-config/textarea.js +6 -1
  17. package/lib/platform/template/wx/component-config/view.js +4 -0
  18. package/lib/platform/template/wx/index.js +127 -1
  19. package/lib/react/processTemplate.js +3 -0
  20. package/lib/resolve-loader.js +4 -1
  21. package/lib/runtime/components/react/context.ts +4 -0
  22. package/lib/runtime/components/react/dist/context.js +1 -0
  23. package/lib/runtime/components/react/dist/event.config.js +24 -24
  24. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -165
  25. package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
  26. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +30 -12
  27. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  28. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  29. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  30. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  31. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  32. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  33. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  34. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  35. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
  36. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  37. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  38. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  39. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  40. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  41. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  42. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  43. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  44. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +110 -97
  45. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +32 -29
  46. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  47. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  48. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  49. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  50. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  51. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
  52. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  53. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
  54. package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
  55. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  56. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  57. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  58. package/lib/runtime/components/react/dist/mpx-view.jsx +29 -44
  59. package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
  60. package/lib/runtime/components/react/dist/pickerFaces.js +12 -6
  61. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  62. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  63. package/lib/runtime/components/react/dist/{pickerOverlay.jsx → pickerViewOverlay.jsx} +5 -3
  64. package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -9
  65. package/lib/runtime/components/react/dist/utils.jsx +20 -24
  66. package/lib/runtime/components/react/getInnerListeners.ts +35 -28
  67. package/lib/runtime/components/react/mpx-button.tsx +55 -36
  68. package/lib/runtime/components/react/mpx-canvas/index.tsx +2 -2
  69. package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -12
  70. package/lib/runtime/components/react/mpx-checkbox.tsx +28 -28
  71. package/lib/runtime/components/react/mpx-form.tsx +10 -8
  72. package/lib/runtime/components/react/mpx-icon.tsx +10 -15
  73. package/lib/runtime/components/react/mpx-image.tsx +396 -0
  74. package/lib/runtime/components/react/mpx-input.tsx +61 -33
  75. package/lib/runtime/components/react/mpx-label.tsx +14 -13
  76. package/lib/runtime/components/react/mpx-movable-area.tsx +8 -7
  77. package/lib/runtime/components/react/mpx-movable-view.tsx +1 -1
  78. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  79. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  80. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  81. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  82. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  83. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  84. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  85. package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
  86. package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
  87. package/lib/runtime/components/react/mpx-radio-group.tsx +11 -12
  88. package/lib/runtime/components/react/mpx-radio.tsx +26 -29
  89. package/lib/runtime/components/react/mpx-scroll-view.tsx +32 -30
  90. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  91. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  92. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  93. package/lib/runtime/components/react/mpx-switch.tsx +10 -8
  94. package/lib/runtime/components/react/mpx-text.tsx +6 -2
  95. package/lib/runtime/components/react/mpx-view.tsx +37 -45
  96. package/lib/runtime/components/react/mpx-web-view.tsx +25 -15
  97. package/lib/runtime/components/react/types/global.d.ts +1 -16
  98. package/lib/runtime/components/react/utils.tsx +24 -24
  99. package/lib/runtime/components/tenon/getInnerListeners.js +334 -0
  100. package/lib/runtime/components/tenon/tenon-button.vue +309 -0
  101. package/lib/runtime/components/tenon/tenon-image.vue +66 -0
  102. package/lib/runtime/components/tenon/tenon-input.vue +171 -0
  103. package/lib/runtime/components/tenon/tenon-rich-text.vue +26 -0
  104. package/lib/runtime/components/tenon/tenon-scroll-view.vue +127 -0
  105. package/lib/runtime/components/tenon/tenon-switch.vue +96 -0
  106. package/lib/runtime/components/tenon/tenon-text.vue +70 -0
  107. package/lib/runtime/components/tenon/tenon-textarea.vue +86 -0
  108. package/lib/runtime/components/tenon/tenon-view.vue +93 -0
  109. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  110. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  111. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  112. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  113. package/lib/runtime/components/web/mpx-web-view.vue +162 -162
  114. package/lib/runtime/optionProcessor.js +7 -16
  115. package/lib/runtime/optionProcessor.tenon.js +84 -0
  116. package/lib/runtime/utils.js +2 -0
  117. package/lib/style-compiler/index.js +1 -1
  118. package/lib/style-compiler/plugins/hm.js +20 -0
  119. package/lib/template-compiler/bind-this.js +7 -2
  120. package/lib/template-compiler/compiler.js +67 -40
  121. package/lib/template-compiler/gen-node-react.js +2 -2
  122. package/lib/tenon/index.js +117 -0
  123. package/lib/tenon/processJSON.js +352 -0
  124. package/lib/tenon/processScript.js +203 -0
  125. package/lib/tenon/processStyles.js +21 -0
  126. package/lib/tenon/processTemplate.js +126 -0
  127. package/lib/tenon/script-helper.js +223 -0
  128. package/lib/utils/env.js +6 -1
  129. package/lib/utils/get-relative-path.js +25 -0
  130. package/package.json +7 -3
  131. package/LICENSE +0 -433
  132. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  133. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  134. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  135. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  136. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  137. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  138. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
@@ -3,184 +3,184 @@
3
3
  </template>
4
4
 
5
5
  <script>
6
- import { getCustomEvent } from './getInnerListeners'
7
- import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
8
- const navObj = promisify({ redirectTo, navigateTo, navigateBack, reLaunch, switchTab })
9
- const eventLoad = 'load'
10
- const eventError = 'error'
11
- const eventMessage = 'message'
12
- const mpx = global.__mpx
13
- export default {
14
- props: {
15
- src: {
16
- type: String
6
+ import { getCustomEvent } from './getInnerListeners'
7
+ import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
8
+ import { extend } from '../../utils'
9
+ const navObj = promisify({ redirectTo, navigateTo, navigateBack, reLaunch, switchTab })
10
+ const eventLoad = 'load'
11
+ const eventError = 'error'
12
+ const eventMessage = 'message'
13
+ const mpx = global.__mpx
14
+ export default {
15
+ props: {
16
+ src: {
17
+ type: String
18
+ }
19
+ },
20
+ computed: {
21
+ host () {
22
+ let host = this.src.split('/')
23
+ if (host[2]) {
24
+ host = host[0] + '//' + host[2]
25
+ } else {
26
+ host = ''
17
27
  }
28
+ return host
18
29
  },
19
- computed: {
20
- host () {
21
- let host = this.src.split('/')
22
- if (host[2]) {
23
- host = host[0] + '//' + host[2]
24
- } else {
25
- host = ''
26
- }
27
- return host
28
- },
29
- currentUrl () {
30
- if (!this.src) return ''
31
- const hostValidate = this.hostValidate(this.host)
32
- if (!hostValidate) {
33
- console.error('访问页面域名不符合domainWhiteLists白名单配置,请确认是否正确配置该域名白名单')
34
- return ''
35
- }
36
- let src
37
- const srcQueryIndex = this.src.indexOf('?')
38
- // webview与被打开页面通过_uid确定关联关系
39
- if (srcQueryIndex > -1) {
40
- src = `${this.src.substring(0, srcQueryIndex + 1)}mpx_webview_id=${this._uid}&${this.src.substring(srcQueryIndex + 1)}`
41
- } else {
42
- src = `${this.src}?mpx_webview_id=${this._uid}`
43
- }
44
- return src
45
- },
46
- loadData () {
47
- return {
48
- src: this.host,
49
- fullUrl: this.src
50
- }
30
+ currentUrl () {
31
+ if (!this.src) return ''
32
+ const hostValidate = this.hostValidate(this.host)
33
+ if (!hostValidate) {
34
+ console.error('访问页面域名不符合domainWhiteLists白名单配置,请确认是否正确配置该域名白名单')
35
+ return ''
51
36
  }
52
- },
53
- watch: {
54
- currentUrl: {
55
- handler (value) {
56
- if (!value) {
57
- this.$emit(eventError, getCustomEvent(eventError, {
58
- ...this.loadData,
59
- errMsg: 'web-view load failed due to not in domain list'
60
- }, this))
61
- } else {
62
- this.$nextTick(() => {
63
- if (this.$refs.mpxIframe && this.mpxIframe != this.$refs.mpxIframe) {
64
- this.mpxIframe = this.$refs.mpxIframe
65
- this.mpxIframe.addEventListener('load', (event) => {
66
- this.$emit(eventLoad, getCustomEvent(eventLoad, this.loadData, this))
67
- })
68
- }
69
- })
70
- }
71
- },
72
- immediate: true
37
+ let src
38
+ const srcQueryIndex = this.src.indexOf('?')
39
+ // webview与被打开页面通过_uid确定关联关系
40
+ if (srcQueryIndex > -1) {
41
+ src = `${this.src.substring(0, srcQueryIndex + 1)}mpx_webview_id=${this._uid}&${this.src.substring(srcQueryIndex + 1)}`
42
+ } else {
43
+ src = `${this.src}?mpx_webview_id=${this._uid}`
73
44
  }
45
+ return src
74
46
  },
75
- beforeCreate () {
76
- this.messageList = []
77
- },
78
- mounted () {
79
- window.addEventListener('message', this.messageCallback)
80
- },
81
- deactivated () {
82
- if (!this.messageList.length) {
83
- return
47
+ loadData () {
48
+ return {
49
+ src: this.host,
50
+ fullUrl: this.src
84
51
  }
85
- let data = {
86
- type: 'message',
87
- data: this.messageList
52
+ }
53
+ },
54
+ watch: {
55
+ currentUrl: {
56
+ handler (value) {
57
+ if (!value) {
58
+ this.$emit(eventError, getCustomEvent(eventError, extend({
59
+ errMsg: 'web-view load failed due to not in domain list'
60
+ }, this.loadData), this))
61
+ } else {
62
+ this.$nextTick(() => {
63
+ if (this.$refs.mpxIframe && this.mpxIframe != this.$refs.mpxIframe) {
64
+ this.mpxIframe = this.$refs.mpxIframe
65
+ this.mpxIframe.addEventListener('load', () => {
66
+ this.$emit(eventLoad, getCustomEvent(eventLoad, this.loadData, this))
67
+ })
68
+ }
69
+ })
70
+ }
71
+ },
72
+ immediate: true
73
+ }
74
+ },
75
+ beforeCreate () {
76
+ this.messageList = []
77
+ },
78
+ mounted () {
79
+ window.addEventListener('message', this.messageCallback)
80
+ },
81
+ deactivated () {
82
+ if (!this.messageList.length) {
83
+ return
84
+ }
85
+ let data = {
86
+ type: 'message',
87
+ data: this.messageList
88
+ }
89
+ this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
90
+ },
91
+ destroyed () {
92
+ window.removeEventListener('message', this.messageCallback)
93
+ if (!this.messageList.length) {
94
+ return
95
+ }
96
+ let data = {
97
+ type: 'message',
98
+ data: this.messageList
99
+ }
100
+ this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
101
+ },
102
+ methods: {
103
+ messageCallback (event) {
104
+ const hostValidate = this.hostValidate(event.origin)
105
+ const data = event.data
106
+ // 判断number类型,防止undefined导致触发return逻辑
107
+ if (data.clientUid !== undefined && +data.clientUid !== this._uid) {
108
+ return
88
109
  }
89
- this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
90
- },
91
- destroyed () {
92
- window.removeEventListener('message', this.messageCallback)
93
- if (!this.messageList.length) {
110
+ let value = data.payload
111
+ if (!hostValidate) {
94
112
  return
95
113
  }
96
- let data = {
97
- type: 'message',
98
- data: this.messageList
114
+ let asyncCallback = null
115
+ switch (data.type) {
116
+ case 'postMessage':
117
+ this.messageList.push(value.data || value)
118
+ asyncCallback = Promise.resolve({
119
+ errMsg: 'invokeWebappApi:ok'
120
+ })
121
+ break
122
+ case 'navigateTo':
123
+ asyncCallback = navObj.navigateTo(value)
124
+ break
125
+ case 'navigateBack':
126
+ asyncCallback = navObj.navigateBack(value)
127
+ break
128
+ case 'redirectTo':
129
+ asyncCallback = navObj.redirectTo(value)
130
+ break
131
+ case 'switchTab':
132
+ asyncCallback = navObj.switchTab(value)
133
+ break
134
+ case 'reLaunch':
135
+ asyncCallback = navObj.reLaunch(value)
136
+ break
137
+ case 'getLocation':
138
+ const getLocation = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations.getLocation
139
+ if (getLocation) {
140
+ asyncCallback = getLocation()
141
+ } else {
142
+ asyncCallback = Promise.reject({
143
+ errMsg: '未在apiImplementations中配置getLocation方法'
144
+ })
145
+ }
146
+ break
99
147
  }
100
- this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
148
+ asyncCallback && asyncCallback.then((res) => {
149
+ this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
150
+ type: data.type,
151
+ callbackId: data.callbackId,
152
+ result: res
153
+ }, event.origin)
154
+ }).catch((error) => {
155
+ this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
156
+ type: data.type,
157
+ callbackId: data.callbackId,
158
+ error
159
+ }, event.origin)
160
+ })
101
161
  },
102
- methods: {
103
- messageCallback (event) {
104
- const hostValidate = this.hostValidate(event.origin)
105
- const data = event.data
106
- // 判断number类型,防止undefined导致触发return逻辑
107
- if (data.clientUid !== undefined && +data.clientUid !== this._uid) {
108
- return
109
- }
110
- let value = data.payload
111
- if (!hostValidate) {
112
- return
113
- }
114
- let asyncCallback = null
115
- switch (data.type) {
116
- case 'postMessage':
117
- this.messageList.push(value.data || value)
118
- asyncCallback = Promise.resolve({
119
- errMsg: 'invokeWebappApi:ok'
120
- })
121
- break
122
- case 'navigateTo':
123
- asyncCallback = navObj.navigateTo(value)
124
- break
125
- case 'navigateBack':
126
- asyncCallback = navObj.navigateBack(value)
127
- break
128
- case 'redirectTo':
129
- asyncCallback = navObj.redirectTo(value)
130
- break
131
- case 'switchTab':
132
- asyncCallback = navObj.switchTab(value)
133
- break
134
- case 'reLaunch':
135
- asyncCallback = navObj.reLaunch(value)
136
- break
137
- case 'getLocation':
138
- const getLocation = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations.getLocation
139
- if (getLocation) {
140
- asyncCallback = getLocation()
141
- } else {
142
- asyncCallback = Promise.reject({
143
- errMsg: '未在apiImplementations中配置getLocation方法'
144
- })
145
- }
146
- break
147
- }
148
- asyncCallback && asyncCallback.then((res) => {
149
- this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
150
- type: data.type,
151
- callbackId: data.callbackId,
152
- result: res
153
- }, event.origin)
154
- }).catch((error) => {
155
- this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
156
- type: data.type,
157
- callbackId: data.callbackId,
158
- error
159
- }, event.origin)
162
+ hostValidate (host) {
163
+ const hostWhitelists = mpx.config.webviewConfig && mpx.config.webviewConfig.hostWhitelists || []
164
+ if (hostWhitelists.length) {
165
+ return hostWhitelists.some((item) => {
166
+ return host.endsWith(item)
160
167
  })
161
- },
162
- hostValidate (host) {
163
- const hostWhitelists = mpx.config.webviewConfig && mpx.config.webviewConfig.hostWhitelists || []
164
- if (hostWhitelists.length) {
165
- return hostWhitelists.some((item) => {
166
- return host.endsWith(item)
167
- })
168
- } else {
169
- return true
170
- }
168
+ } else {
169
+ return true
171
170
  }
172
171
  }
173
172
  }
173
+ }
174
174
  </script>
175
175
 
176
176
  <style>
177
- .mpx-iframe {
178
- width: 100%;
179
- height: 100%;
180
- position: absolute;
181
- left: 0;
182
- top: 0;
183
- right: 0;
184
- bottom: 0;
185
- }
177
+ .mpx-iframe {
178
+ width: 100%;
179
+ height: 100%;
180
+ position: absolute;
181
+ left: 0;
182
+ top: 0;
183
+ right: 0;
184
+ bottom: 0;
185
+ }
186
186
  </style>
@@ -1,4 +1,4 @@
1
- import { hasOwn, isEmptyObject } from './utils'
1
+ import { hasOwn, isEmptyObject, extend } from './utils'
2
2
  import { isBrowser } from './env'
3
3
  import transRpxStyle from './transRpxStyle'
4
4
  import animation from './animation'
@@ -59,7 +59,7 @@ registered in parent context!`)
59
59
  }
60
60
 
61
61
  if (ctorType === 'page') {
62
- option.__mpxPageConfig = Object.assign({}, global.__mpxPageConfig, pageConfig)
62
+ option.__mpxPageConfig = extend({}, global.__mpxPageConfig, pageConfig)
63
63
  }
64
64
 
65
65
  if (!hasApp) {
@@ -109,7 +109,7 @@ registered in parent context!`)
109
109
  export function getComponent (component, extendOptions) {
110
110
  component = component.__esModule ? component.default : component
111
111
  // eslint-disable-next-line
112
- if (extendOptions) Object.assign(component, extendOptions)
112
+ if (extendOptions) extend(component, extendOptions)
113
113
  return component
114
114
  }
115
115
 
@@ -164,10 +164,7 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
164
164
  })
165
165
  }
166
166
  const webRouteConfig = global.__mpx.config.webConfig.routeConfig || global.__mpx.config.webRouteConfig
167
- global.__mpxRouter = option.router = new VueRouter({
168
- ...webRouteConfig,
169
- routes: routes
170
- })
167
+ global.__mpxRouter = option.router = new VueRouter(extend({ routes }, webRouteConfig))
171
168
  let mpxStackPath = []
172
169
  if (isBrowser) {
173
170
  // 解决webview被刷新导致路由栈丢失后产生错乱问题
@@ -365,7 +362,7 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
365
362
 
366
363
  if (App.onAppInit) {
367
364
  global.__mpxAppInit = true
368
- Object.assign(option, App.onAppInit() || {})
365
+ extend(option, App.onAppInit() || {})
369
366
  global.__mpxAppInit = false
370
367
  }
371
368
 
@@ -374,14 +371,8 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
374
371
  option.pinia = global.__mpxPinia
375
372
  }
376
373
 
377
- const app = new Vue({
378
- ...option,
379
- render: (h) => h(App)
380
- })
381
- return {
382
- app,
383
- ...option
384
- }
374
+ const app = new Vue(extend(option, { render: (h) => h(App) }))
375
+ return extend({ app }, option)
385
376
  }
386
377
 
387
378
  export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue, VueRouter, tabBarMap, el }) {
@@ -0,0 +1,84 @@
1
+ // import { inBrowser } from '../utils/env'
2
+
3
+ import { hasOwn } from './utils'
4
+
5
+ export function processComponentOption (
6
+ {
7
+ option,
8
+ ctorType,
9
+ outputPath,
10
+ pageConfig,
11
+ componentsMap,
12
+ componentGenerics,
13
+ genericsInfo,
14
+ wxsMixin,
15
+ hasApp,
16
+ }
17
+ ) {
18
+ if (ctorType === 'app') {
19
+ // 对于app中的组件需要全局注册
20
+ for (const componentName in componentsMap) {
21
+ if (hasOwn(componentsMap, componentName)) {
22
+ const component = componentsMap[componentName]
23
+ Vue.component(componentName, component)
24
+ }
25
+ }
26
+ } else {
27
+ // 局部注册页面和组件中依赖的组件
28
+ for (const componentName in componentsMap) {
29
+ if (hasOwn(componentsMap, componentName)) {
30
+ const component = componentsMap[componentName]
31
+ if (!option.components) {
32
+ option.components = {}
33
+ }
34
+ option.components[componentName] = component
35
+ }
36
+ }
37
+
38
+ if (ctorType === 'page') {
39
+ (option.mixins ? option.mixins : (option.mixins = [])).push({
40
+ // cache page instance in tenon
41
+ created () {
42
+ global.__currentPageInstance = this
43
+ }
44
+ })
45
+ option.__mpxPageConfig = Object.assign({}, global.__mpxPageConfig, pageConfig)
46
+ }
47
+ }
48
+
49
+ if (wxsMixin) {
50
+ if (option.mixins) {
51
+ option.mixins.push(mixin)
52
+ } else {
53
+ option.mixins = [mixin]
54
+ }
55
+ }
56
+
57
+ if (outputPath) {
58
+ option.componentPath = '/' + outputPath
59
+ }
60
+
61
+ return option
62
+ }
63
+
64
+ export function getComponent (component, extendOptions) {
65
+ component = component.__esModule ? component.default : component
66
+ // eslint-disable-next-line
67
+ if (extendOptions) Object.assign(component, extendOptions)
68
+ return component
69
+ }
70
+
71
+ export function getWxsMixin (wxsModules) {
72
+ if (!wxsModules) return {}
73
+ return {
74
+ created () {
75
+ Object.keys(wxsModules).forEach((key) => {
76
+ if (key in this) {
77
+ console.error(`[Mpx runtime error]: The wxs module key [${key}] exist in the component/page instance already, please check and rename it!`)
78
+ } else {
79
+ this[key] = wxsModules[key]
80
+ }
81
+ })
82
+ }
83
+ }
84
+ }
@@ -45,3 +45,5 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
45
45
  export function hasOwn (obj, key) {
46
46
  return hasOwnProperty.call(obj, key)
47
47
  }
48
+
49
+ export const extend = Object.assign
@@ -30,7 +30,7 @@ module.exports = function (css, map) {
30
30
  const index = queryObj.index || 0
31
31
  const packageName = queryObj.packageRoot || mpx.currentPackageRoot || 'main'
32
32
 
33
- const transRpxFn = mpx.webConfig.transRpxFn
33
+ const transRpxFn = mpx.webConfig && mpx.webConfig.transRpxFn
34
34
  const testResolveRange = (include = () => true, exclude) => {
35
35
  return matchCondition(this.resourcePath, { include, exclude })
36
36
  }
@@ -0,0 +1,20 @@
1
+ const postcss = require('postcss')
2
+ const rpxRegExp = /\b(\d+(\.\d+)?)rpx\b/
3
+ const rpxRegExpG = /\b(\d+(\.\d+)?)rpx\b/g
4
+
5
+ module.exports = postcss.plugin('hm', (options = {}) => root => {
6
+ function transHm (declaration) {
7
+ if (rpxRegExp.test(declaration.value)) {
8
+ declaration.value = declaration.value.replace(rpxRegExpG, function (match, $1) {
9
+ if ($1 === '0') return $1
10
+ return `${$1}hm`
11
+ })
12
+ }
13
+ }
14
+
15
+ root.walkRules(rule => {
16
+ rule.walkDecls(declaration => {
17
+ transHm(declaration)
18
+ })
19
+ })
20
+ })
@@ -264,7 +264,8 @@ module.exports = {
264
264
  transform (code, {
265
265
  needCollect = false,
266
266
  renderReduce = false,
267
- ignoreMap = {}
267
+ ignoreMap = {},
268
+ customBindThis
268
269
  } = {}) {
269
270
  const ast = babylon.parse(code, {
270
271
  plugins: [
@@ -420,7 +421,11 @@ module.exports = {
420
421
  if (isProps) {
421
422
  propKeySet.add(name)
422
423
  }
423
- path.replaceWith(t.memberExpression(t.thisExpression(), path.node))
424
+ if (typeof customBindThis === 'function') {
425
+ customBindThis(path, t)
426
+ } else {
427
+ path.replaceWith(t.memberExpression(t.thisExpression(), path.node))
428
+ }
424
429
  }
425
430
  delete path.needBind
426
431
  }