@mpxjs/webpack-plugin 2.10.16 → 2.10.17-beta.10

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 (226) hide show
  1. package/lib/config.js +60 -0
  2. package/lib/dependencies/AppEntryDependency.js +2 -2
  3. package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
  4. package/lib/dependencies/ResolveDependency.js +1 -1
  5. package/lib/file-loader.js +4 -1
  6. package/lib/global.d.ts +245 -0
  7. package/lib/helpers.js +2 -0
  8. package/lib/index.js +80 -19
  9. package/lib/json-compiler/helper.js +72 -2
  10. package/lib/json-compiler/index.js +45 -59
  11. package/lib/json-compiler/plugin.js +2 -2
  12. package/lib/loader.js +14 -4
  13. package/lib/native-loader.js +6 -3
  14. package/lib/platform/json/wx/index.js +30 -29
  15. package/lib/platform/style/wx/index.js +51 -36
  16. package/lib/platform/template/wx/component-config/ad.js +5 -0
  17. package/lib/platform/template/wx/component-config/button.js +22 -6
  18. package/lib/platform/template/wx/component-config/camera.js +25 -3
  19. package/lib/platform/template/wx/component-config/canvas.js +8 -1
  20. package/lib/platform/template/wx/component-config/component.js +31 -33
  21. package/lib/platform/template/wx/component-config/cover-image.js +7 -2
  22. package/lib/platform/template/wx/component-config/cover-view.js +3 -1
  23. package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
  24. package/lib/platform/template/wx/component-config/form.js +27 -2
  25. package/lib/platform/template/wx/component-config/image.js +5 -0
  26. package/lib/platform/template/wx/component-config/input.js +11 -1
  27. package/lib/platform/template/wx/component-config/label.js +10 -2
  28. package/lib/platform/template/wx/component-config/map.js +11 -0
  29. package/lib/platform/template/wx/component-config/movable-area.js +4 -1
  30. package/lib/platform/template/wx/component-config/movable-view.js +17 -2
  31. package/lib/platform/template/wx/component-config/navigator.js +26 -0
  32. package/lib/platform/template/wx/component-config/picker-view.js +12 -0
  33. package/lib/platform/template/wx/component-config/picker.js +3 -1
  34. package/lib/platform/template/wx/component-config/progress.js +11 -1
  35. package/lib/platform/template/wx/component-config/rich-text.js +5 -0
  36. package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
  37. package/lib/platform/template/wx/component-config/slider.js +8 -0
  38. package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
  39. package/lib/platform/template/wx/component-config/swiper.js +10 -0
  40. package/lib/platform/template/wx/component-config/text.js +5 -0
  41. package/lib/platform/template/wx/component-config/textarea.js +20 -3
  42. package/lib/platform/template/wx/component-config/unsupported.js +10 -1
  43. package/lib/platform/template/wx/component-config/video.js +10 -0
  44. package/lib/platform/template/wx/index.js +21 -1
  45. package/lib/react/LoadAsyncChunkModule.js +1 -1
  46. package/lib/react/index.js +2 -0
  47. package/lib/react/processJSON.js +59 -72
  48. package/lib/react/processScript.js +1 -0
  49. package/lib/react/processStyles.js +24 -11
  50. package/lib/react/processTemplate.js +8 -6
  51. package/lib/react/script-helper.js +6 -17
  52. package/lib/react/style-helper.js +84 -13
  53. package/lib/resolver/AddModePlugin.js +23 -8
  54. package/lib/runtime/components/ali/mpx-recycle-view.mpx +518 -0
  55. package/lib/runtime/components/ali/mpx-sticky-header.mpx +212 -0
  56. package/lib/runtime/components/ali/mpx-sticky-section.mpx +17 -0
  57. package/lib/runtime/components/react/animationHooks/index.ts +75 -0
  58. package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +198 -0
  59. package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +301 -0
  60. package/lib/runtime/components/react/animationHooks/utils.ts +197 -0
  61. package/lib/runtime/components/react/context.ts +19 -7
  62. package/lib/runtime/components/react/dist/animationHooks/index.d.ts +15 -0
  63. package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
  64. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +3 -0
  65. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +182 -0
  66. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +3 -0
  67. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +279 -0
  68. package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +109 -0
  69. package/lib/runtime/components/react/dist/animationHooks/utils.js +151 -0
  70. package/lib/runtime/components/react/dist/context.d.ts +79 -0
  71. package/lib/runtime/components/react/dist/context.js +1 -0
  72. package/lib/runtime/components/react/dist/event.config.d.ts +7 -0
  73. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +7 -0
  74. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +12 -0
  75. package/lib/runtime/components/react/dist/mpx-button.d.ts +68 -0
  76. package/lib/runtime/components/react/dist/mpx-camera.d.ts +31 -0
  77. package/lib/runtime/components/react/dist/mpx-camera.jsx +236 -0
  78. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +23 -0
  79. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +7 -0
  80. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +6 -0
  81. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +20 -0
  82. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +8 -0
  83. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +10 -0
  84. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +2 -0
  85. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +32 -0
  86. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
  87. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +52 -0
  88. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +20 -0
  89. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +32 -0
  90. package/lib/runtime/components/react/dist/mpx-form.d.ts +27 -0
  91. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +18 -0
  92. package/lib/runtime/components/react/dist/mpx-image.d.ts +21 -0
  93. package/lib/runtime/components/react/dist/mpx-image.jsx +109 -59
  94. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +7 -0
  95. package/lib/runtime/components/react/dist/mpx-input.d.ts +51 -0
  96. package/lib/runtime/components/react/dist/mpx-input.jsx +52 -17
  97. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +12 -0
  98. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +62 -49
  99. package/lib/runtime/components/react/dist/mpx-label.d.ts +20 -0
  100. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +20 -0
  101. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +65 -0
  102. package/lib/runtime/components/react/dist/mpx-nav.d.ts +8 -0
  103. package/lib/runtime/components/react/dist/mpx-nav.jsx +132 -0
  104. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +9 -0
  105. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +6 -0
  106. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +7 -0
  107. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +6 -0
  108. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +6 -0
  109. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +6 -0
  110. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +2 -0
  111. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +6 -0
  112. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +6 -0
  113. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +106 -0
  114. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +32 -0
  115. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +4 -3
  116. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +8 -0
  117. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +23 -0
  118. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +12 -18
  119. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +14 -0
  120. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +8 -11
  121. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +13 -0
  122. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +20 -0
  123. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +16 -0
  124. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +12 -0
  125. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +11 -0
  126. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +22 -0
  127. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +16 -0
  128. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +15 -0
  129. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
  130. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +29 -0
  131. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +9 -0
  132. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
  133. package/lib/runtime/components/react/dist/mpx-progress.d.ts +23 -0
  134. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +20 -0
  135. package/lib/runtime/components/react/dist/mpx-radio.d.ts +26 -0
  136. package/lib/runtime/components/react/dist/mpx-recycle-view.d.ts +45 -0
  137. package/lib/runtime/components/react/dist/mpx-recycle-view.jsx +307 -0
  138. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +1 -0
  139. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +24 -0
  140. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -1
  141. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +14 -0
  142. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +54 -0
  143. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
  144. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +7 -0
  145. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +7 -0
  146. package/lib/runtime/components/react/dist/mpx-slider.d.ts +30 -0
  147. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +17 -0
  148. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +15 -0
  149. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +18 -0
  150. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +63 -0
  151. package/lib/runtime/components/react/dist/mpx-swiper.jsx +77 -44
  152. package/lib/runtime/components/react/dist/mpx-switch.d.ts +26 -0
  153. package/lib/runtime/components/react/dist/mpx-text.d.ts +22 -0
  154. package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
  155. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +7 -0
  156. package/lib/runtime/components/react/dist/mpx-video.d.ts +101 -0
  157. package/lib/runtime/components/react/dist/mpx-view.d.ts +35 -0
  158. package/lib/runtime/components/react/dist/mpx-view.jsx +23 -9
  159. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +22 -0
  160. package/lib/runtime/components/react/dist/mpx-web-view.jsx +11 -3
  161. package/lib/runtime/components/react/dist/parser.d.ts +39 -0
  162. package/lib/runtime/components/react/dist/useNodesRef.d.ts +11 -0
  163. package/lib/runtime/components/react/dist/utils.d.ts +124 -0
  164. package/lib/runtime/components/react/dist/utils.jsx +42 -17
  165. package/lib/runtime/components/react/mpx-camera.tsx +327 -0
  166. package/lib/runtime/components/react/mpx-canvas/index.tsx +1 -1
  167. package/lib/runtime/components/react/mpx-image.tsx +132 -79
  168. package/lib/runtime/components/react/mpx-input.tsx +63 -24
  169. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +70 -48
  170. package/lib/runtime/components/react/mpx-nav.tsx +155 -0
  171. package/lib/runtime/components/react/mpx-picker-view/index.tsx +5 -2
  172. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +26 -21
  173. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +8 -12
  174. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +55 -0
  175. package/lib/runtime/components/react/mpx-portal/index.tsx +8 -2
  176. package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
  177. package/lib/runtime/components/react/mpx-recycle-view.tsx +437 -0
  178. package/lib/runtime/components/react/mpx-rich-text/index.tsx +1 -1
  179. package/lib/runtime/components/react/mpx-scroll-view.tsx +7 -17
  180. package/lib/runtime/components/react/mpx-sticky-section.tsx +1 -1
  181. package/lib/runtime/components/react/mpx-swiper.tsx +92 -42
  182. package/lib/runtime/components/react/mpx-text.tsx +38 -5
  183. package/lib/runtime/components/react/mpx-view.tsx +28 -13
  184. package/lib/runtime/components/react/mpx-web-view.tsx +14 -5
  185. package/lib/runtime/components/react/tsconfig.json +26 -0
  186. package/lib/runtime/components/react/types/common.d.ts +19 -0
  187. package/lib/runtime/components/react/types/global.d.ts +1 -0
  188. package/lib/runtime/components/react/utils.tsx +43 -21
  189. package/lib/runtime/components/web/mpx-recycle-view.vue +508 -0
  190. package/lib/runtime/components/wx/mpx-list-header-default.mpx +21 -0
  191. package/lib/runtime/components/wx/mpx-recycle-item-default.mpx +21 -0
  192. package/lib/runtime/components/wx/mpx-recycle-view.mpx +193 -0
  193. package/lib/runtime/components/wx/mpx-section-header-default.mpx +21 -0
  194. package/lib/runtime/optionProcessor.js +5 -0
  195. package/lib/runtime/optionProcessorReact.js +7 -0
  196. package/lib/runtime/stringify.wxs +2 -2
  197. package/lib/script-setup-compiler/index.js +2 -2
  198. package/lib/style-compiler/index.js +3 -2
  199. package/lib/style-compiler/load-postcss-config.js +1 -1
  200. package/lib/style-compiler/plugins/trans-special.js +10 -2
  201. package/lib/style-compiler/strip-conditional-loader/rebaseUrl.js +225 -0
  202. package/lib/style-compiler/strip-conditional-loader.js +124 -18
  203. package/lib/template-compiler/compiler.js +272 -72
  204. package/lib/template-compiler/gen-node-react.js +18 -6
  205. package/lib/template-compiler/index.js +6 -4
  206. package/lib/template-compiler/parse-exps.js +1 -1
  207. package/lib/utils/const.js +19 -1
  208. package/lib/utils/dom-tag-config.js +6 -6
  209. package/lib/utils/env.js +6 -1
  210. package/lib/utils/get-build-tag-component.js +35 -0
  211. package/lib/utils/merge-visitors.js +55 -0
  212. package/lib/utils/pre-process-json.js +5 -0
  213. package/lib/utils/process-extend-components.js +43 -0
  214. package/lib/utils/string.js +25 -1
  215. package/lib/web/index.js +2 -0
  216. package/lib/web/processJSON.js +64 -18
  217. package/lib/web/processScript.js +1 -1
  218. package/lib/web/processTemplate.js +6 -4
  219. package/lib/web/script-helper.js +19 -9
  220. package/lib/wxs/pre-loader.js +9 -6
  221. package/lib/wxss/loader.js +1 -9
  222. package/package.json +11 -7
  223. package/LICENSE +0 -433
  224. package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
  225. package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
  226. package/lib/utils/chain-assign.js +0 -47
@@ -74,10 +74,10 @@ const isNativeMiniTag = makeMap(
74
74
  */
75
75
  const isBuildInWebTag = makeMap(
76
76
  'mpx-image,mpx-picker-view,mpx-slider,mpx-textarea,mpx-input,mpx-picker,' +
77
- 'mpx-swiper-item,mpx-video,mpx-button,mpx-keep-alive,mpx-progress,' +
77
+ 'mpx-swiper-item,mpx-video,mpx-button,mpx-progress,' +
78
78
  'mpx-swiper,mpx-view,mpx-checkbox-group,mpx-movable-area,mpx-radio-group,' +
79
79
  'mpx-switch,mpx-web-view,mpx-checkbox,mpx-movable-view,mpx-radio,' +
80
- 'mpx-tab-bar-container,mpx-form,mpx-navigator,mpx-rich-text,mpx-tab-bar,' +
80
+ 'mpx-form,mpx-navigator,mpx-rich-text,' +
81
81
  'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text'
82
82
  )
83
83
 
@@ -86,12 +86,12 @@ const isBuildInWebTag = makeMap(
86
86
  */
87
87
  const isBuildInReactTag = makeMap(
88
88
  'mpx-web-view,mpx-view,mpx-video,mpx-textarea,mpx-text,mpx-switch,' +
89
- 'mpx-swiper,mpx-swiper-item,mpx-simple-view,mpx-simple-text,mpx-scroll-view,' +
89
+ 'mpx-swiper,mpx-swiper-item,mpx-scroll-view,' +
90
90
  'mpx-root-portal,mpx-radio,mpx-radio-group,mpx-navigator,mpx-movable-view,' +
91
- 'mpx-movable-area,mpx-label,mpx-keyboard-avoiding-view,mpx-input,mpx-inline-text,' +
91
+ 'mpx-movable-area,mpx-label,mpx-input,' +
92
92
  'mpx-image,mpx-form,mpx-checkbox,mpx-checkbox-group,mpx-button,' +
93
- 'mpx-rich-text,mpx-portal,mpx-popup,mpx-picker-view-column,mpx-picker-view,mpx-picker,' +
94
- 'mpx-icon,mpx-canvas'
93
+ 'mpx-rich-text,mpx-picker-view-column,mpx-picker-view,mpx-picker,' +
94
+ 'mpx-icon,mpx-canvas,mpx-camera'
95
95
  )
96
96
 
97
97
  const isSpace = makeMap('ensp,emsp,nbsp')
package/lib/utils/env.js CHANGED
@@ -10,8 +10,13 @@ function isMiniProgram (mode) {
10
10
  return !isWeb(mode) && !isReact(mode)
11
11
  }
12
12
 
13
+ function isNoMode (mode) {
14
+ return mode === 'noMode'
15
+ }
16
+
13
17
  module.exports = {
14
18
  isWeb,
15
19
  isReact,
16
- isMiniProgram
20
+ isMiniProgram,
21
+ isNoMode
17
22
  }
@@ -0,0 +1,35 @@
1
+ const normalize = require('./normalize')
2
+ const { isBuildInWebTag, isBuildInReactTag } = require('./dom-tag-config')
3
+
4
+ module.exports = function getBuildInTagComponent (mode, tag) {
5
+ const aliBuildTag = ['view', 'text'].reduce((obj, name) => {
6
+ obj[name] = {
7
+ name: `mpx-${name}`,
8
+ resource: normalize.lib(`runtime/components/ali/mpx-${name}.mpx`)
9
+ }
10
+ return obj
11
+ }, {})
12
+
13
+ switch (mode) {
14
+ case 'ali':
15
+ return aliBuildTag[tag]
16
+ case 'web':
17
+ if (isBuildInWebTag(`mpx-${tag}`)) {
18
+ return {
19
+ name: `mpx-${tag}`,
20
+ resource: normalize.lib(`runtime/components/web/mpx-${tag}.vue`)
21
+ }
22
+ }
23
+ return undefined
24
+ case 'ios':
25
+ case 'android':
26
+ case 'harmony':
27
+ if (isBuildInReactTag(`mpx-${tag}`)) {
28
+ return {
29
+ name: `mpx-${tag}`,
30
+ resource: normalize.lib(`runtime/components/react/dist/mpx-${tag}.jsx`)
31
+ }
32
+ }
33
+ return undefined
34
+ }
35
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * 链式合并方法的工具函数
3
+ *
4
+ * 在多条件分支下使用 Object.assign 会导致同名方法被覆盖,
5
+ * 这个函数通过创建组合函数来确保所有方法都能按顺序执行。
6
+ *
7
+ * @param {Object} target - 目标 visitor 对象
8
+ * @param {Object} source - 要链式分配的 visitor 方法对象
9
+ **/
10
+
11
+ // 辅助函数:将 visitor 的所有钩子添加到结果中
12
+ function mergeVisitorHooks (result, visitor) {
13
+ result.enter = result.enter.concat(visitor.enter)
14
+ result.exit = result.exit.concat(visitor.exit)
15
+ return result
16
+ }
17
+
18
+ function normalizeVisitor(visitor) {
19
+ if (Array.isArray(visitor.enter) && Array.isArray(visitor.exit)) {
20
+ return visitor
21
+ }
22
+ if (typeof visitor === 'function') {
23
+ return { enter: [visitor], exit: [] }
24
+ }
25
+
26
+ if (visitor.enter) {
27
+ if (!Array.isArray(visitor.enter)) {
28
+ visitor.enter = [visitor.enter]
29
+ }
30
+ } else {
31
+ visitor.enter = []
32
+ }
33
+
34
+ if (visitor.exit) {
35
+ if (!Array.isArray(visitor.exit)) {
36
+ visitor.exit = [visitor.exit]
37
+ }
38
+ } else {
39
+ visitor.exit = []
40
+ }
41
+ return visitor
42
+ }
43
+
44
+ module.exports = function mergeVisitors (target, source) {
45
+ for (const [key, value] of Object.entries(source)) {
46
+ if (!target[key]) {
47
+ target[key] = normalizeVisitor(value)
48
+ } else {
49
+ // 合并现有值和新值
50
+ target[key] = mergeVisitorHooks(normalizeVisitor(target[key]), normalizeVisitor(value))
51
+ }
52
+ }
53
+
54
+ return target
55
+ }
@@ -31,6 +31,7 @@ module.exports = function ({
31
31
  let componentGenerics = {}
32
32
  const usingComponentsInfo = {}
33
33
  const usingComponents = {}
34
+ let originalUsingComponents
34
35
  const finalCallback = (err) => {
35
36
  if (err) return callback(err)
36
37
  if (ctorType === 'app') {
@@ -43,6 +44,7 @@ module.exports = function ({
43
44
  componentPlaceholder,
44
45
  componentGenerics,
45
46
  usingComponentsInfo: Object.assign({}, usingComponentsInfo, mpx.globalComponentsInfo),
47
+ originalUsingComponents,
46
48
  jsonContent
47
49
  })
48
50
  }
@@ -61,6 +63,9 @@ module.exports = function ({
61
63
  if (ctorType !== 'app') {
62
64
  rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
63
65
  }
66
+
67
+ originalUsingComponents = ret.usingComponents ? Object.keys(ret.usingComponents) : []
68
+
64
69
  const rulesRunner = getRulesRunner(rulesRunnerOptions)
65
70
  try {
66
71
  if (rulesRunner) rulesRunner(ret)
@@ -0,0 +1,43 @@
1
+ const { EXTEND_COMPONENT_CONFIG } = require('./const')
2
+ const normalize = require('./normalize')
3
+
4
+ /**
5
+ * 处理扩展组件的公共方法
6
+ * @param {Object} options 配置选项
7
+ * @param {Object} options.useExtendComponents 使用的扩展组件配置
8
+ * @param {string} options.mode 当前模式 (wx, ali, web, rn 等)
9
+ * @param {Function} options.emitWarning 警告函数
10
+ * @returns {Object} 扩展组件映射对象
11
+ */
12
+ function processExtendComponents (options) {
13
+ const {
14
+ useExtendComponents = {},
15
+ mode,
16
+ emitWarning
17
+ } = options
18
+
19
+ if (!useExtendComponents[mode]) {
20
+ return {}
21
+ }
22
+
23
+ const extendComponents = {}
24
+
25
+ useExtendComponents[mode].forEach((name) => {
26
+ // 从配置中获取该组件在当前平台的具体路径
27
+ const componentConfig = EXTEND_COMPONENT_CONFIG[name]
28
+
29
+ if (componentConfig && componentConfig[mode]) {
30
+ extendComponents[name] = normalize.lib(componentConfig[mode])
31
+ } else if (componentConfig) {
32
+ emitWarning('extend component ' + name + ' is not configured for ' + mode + ' environment!')
33
+ } else {
34
+ emitWarning('extend component ' + name + ' is not supported in any environment!')
35
+ }
36
+ })
37
+
38
+ return extendComponents
39
+ }
40
+
41
+ module.exports = {
42
+ processExtendComponents
43
+ }
@@ -28,9 +28,33 @@ function trimBlankRow (str) {
28
28
  return str.replace(/^\s*[\r\n]/gm, '')
29
29
  }
30
30
 
31
+ // 多value解析
32
+ function parseValues (str, char = ' ') {
33
+ let stack = 0
34
+ let temp = ''
35
+ const result = []
36
+ for (let i = 0; i < str.length; i++) {
37
+ if (str[i] === '(') {
38
+ stack++
39
+ } else if (str[i] === ')') {
40
+ stack--
41
+ }
42
+ // 非括号内 或者 非分隔字符且非空
43
+ if (stack !== 0 || str[i] !== char) {
44
+ temp += str[i]
45
+ }
46
+ if ((stack === 0 && str[i] === char) || i === str.length - 1) {
47
+ result.push(temp.trim())
48
+ temp = ''
49
+ }
50
+ }
51
+ return result
52
+ }
53
+
31
54
  module.exports = {
32
55
  isCapital,
33
56
  isMustache,
34
57
  capitalToHyphen,
35
- trimBlankRow
58
+ trimBlankRow,
59
+ parseValues
36
60
  }
package/lib/web/index.js CHANGED
@@ -21,6 +21,7 @@ module.exports = function ({
21
21
  hasComment,
22
22
  isNative,
23
23
  usingComponentsInfo,
24
+ originalUsingComponents,
24
25
  componentGenerics,
25
26
  autoScope,
26
27
  callback
@@ -70,6 +71,7 @@ module.exports = function ({
70
71
  moduleId,
71
72
  ctorType,
72
73
  usingComponentsInfo,
74
+ originalUsingComponents,
73
75
  componentGenerics
74
76
  }, callback)
75
77
  },
@@ -11,6 +11,7 @@ const resolve = require('../utils/resolve')
11
11
  const createJSONHelper = require('../json-compiler/helper')
12
12
  const getRulesRunner = require('../platform/index')
13
13
  const { RESOLVE_IGNORED_ERR } = require('../utils/const')
14
+ const { processExtendComponents } = require('../utils/process-extend-components')
14
15
  const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
15
16
 
16
17
  module.exports = function (jsonContent, {
@@ -30,30 +31,53 @@ module.exports = function (jsonContent, {
30
31
  mode,
31
32
  srcMode,
32
33
  env,
33
- projectRoot
34
+ projectRoot,
35
+ useExtendComponents = {},
36
+ appInfo
34
37
  } = mpx
35
38
 
36
39
  const context = loaderContext.context
37
40
 
41
+ let hasApp = true
42
+
43
+ if (!appInfo.name) {
44
+ hasApp = false
45
+ }
46
+
38
47
  const emitWarning = (msg) => {
39
48
  loaderContext.emitWarning(
40
- new Error('[json processor][' + loaderContext.resource + ']: ' + msg)
49
+ new Error('[Mpx json warning][' + loaderContext.resource + ']: ' + msg)
41
50
  )
42
51
  }
43
52
 
44
53
  const emitError = (msg) => {
45
54
  loaderContext.emitError(
46
- new Error('[json compiler][' + loaderContext.resource + ']: ' + msg)
55
+ new Error('[Mpx json error][' + loaderContext.resource + ']: ' + msg)
47
56
  )
48
57
  }
49
58
 
50
59
  const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
51
60
 
61
+ function fillInComponentsMap (name, entry, tarRoot) {
62
+ const { resource, outputPath } = entry
63
+ const { resourcePath } = parseRequest(resource)
64
+ componentsMap[resourcePath] = outputPath
65
+ loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
66
+ localComponentsMap[name] = {
67
+ resource: addQuery(resource, {
68
+ isComponent: true,
69
+ outputPath
70
+ }),
71
+ async: tarRoot
72
+ }
73
+ }
74
+
52
75
  const {
53
76
  isUrlRequest,
54
77
  urlToRequest,
55
78
  processPage,
56
- processComponent
79
+ processComponent,
80
+ processPlaceholder
57
81
  } = createJSONHelper({
58
82
  loaderContext,
59
83
  emitWarning,
@@ -101,7 +125,16 @@ module.exports = function (jsonContent, {
101
125
  if (ctorType !== 'app') {
102
126
  rulesRunnerOptions.mainKey = ctorType
103
127
  }
104
-
128
+ if (!hasApp || ctorType === 'app') {
129
+ if (useExtendComponents[mode]) {
130
+ const extendComponents = processExtendComponents({
131
+ useExtendComponents,
132
+ mode,
133
+ emitWarning
134
+ })
135
+ jsonObj.usingComponents = Object.assign({}, extendComponents, jsonObj.usingComponents)
136
+ }
137
+ }
105
138
  const rulesRunner = getRulesRunner(rulesRunnerOptions)
106
139
 
107
140
  if (rulesRunner) {
@@ -240,7 +273,7 @@ module.exports = function (jsonContent, {
240
273
  if (oldResourcePath !== resourcePath) {
241
274
  const oldOutputPath = outputPath
242
275
  outputPath = mpx.getOutputPath(resourcePath, 'page', { conflictPath: outputPath })
243
- emitWarning(new Error(`Current page [${resourcePath}] is registered with a conflict outputPath [${oldOutputPath}] which is already existed in system, will be renamed with [${outputPath}], use ?resolve to get the real outputPath!`))
276
+ emitWarning(`Current page [${resourcePath}] is registered with a conflict outputPath [${oldOutputPath}] which is already existed in system, will be renamed with [${outputPath}], use ?resolve to get the real outputPath!`)
244
277
  }
245
278
  }
246
279
 
@@ -287,22 +320,35 @@ module.exports = function (jsonContent, {
287
320
 
288
321
  const processComponents = (components, context, callback) => {
289
322
  if (components) {
323
+ const asyncComponents = []
324
+ const resolveResourcePathMap = new Map()
290
325
  async.eachOf(components, (component, name, callback) => {
291
- processComponent(component, context, {}, (err, { resource, outputPath } = {}, { tarRoot } = {}) => {
326
+ processComponent(component, context, {}, (err, entry = {}, { tarRoot, placeholder, resourcePath } = {}) => {
292
327
  if (err) return callback(err === RESOLVE_IGNORED_ERR ? null : err)
293
- const { resourcePath, queryObj } = parseRequest(resource)
294
- componentsMap[resourcePath] = outputPath
295
- loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
296
- localComponentsMap[name] = {
297
- resource: addQuery(resource, {
298
- isComponent: true,
299
- outputPath
300
- }),
301
- async: queryObj.async || tarRoot
302
- }
328
+ const { relativePath, resource } = entry
329
+ const { queryObj } = parseRequest(resource)
330
+
331
+ tarRoot = queryObj.async || tarRoot
332
+
333
+ resolveResourcePathMap.set(name, resourcePath)
334
+ if (tarRoot) asyncComponents.push({ name, tarRoot, placeholder, relativePath })
335
+
336
+ fillInComponentsMap(name, entry, tarRoot)
303
337
  callback()
304
338
  })
305
- }, callback)
339
+ }, (err) => {
340
+ if (err) return callback(err)
341
+ async.each(asyncComponents, ({ name, tarRoot, placeholder, relativePath }, callback) => {
342
+ processPlaceholder({ jsonObj, context, name, tarRoot, placeholder, relativePath, resolveResourcePathMap }, (err, placeholder) => {
343
+ if (err) return callback(err)
344
+ if (placeholder) {
345
+ const { name, entry } = placeholder
346
+ fillInComponentsMap(name, entry, '')
347
+ }
348
+ callback()
349
+ })
350
+ }, callback)
351
+ })
306
352
  } else {
307
353
  callback()
308
354
  }
@@ -78,12 +78,12 @@ module.exports = function (script, {
78
78
  }
79
79
  content += getRequireScript({ ctorType, script, loaderContext })
80
80
  content += `
81
+ // @ts-ignore
81
82
  export default processComponentOption({
82
83
  option: global.__mpxOptionsMap[${JSON.stringify(moduleId)}],
83
84
  ctorType: ${JSON.stringify(ctorType)},
84
85
  outputPath: ${JSON.stringify(outputPath)},
85
86
  pageConfig: ${JSON.stringify(pageConfig)},
86
- // @ts-ignore
87
87
  componentsMap: ${shallowStringify(componentsMap)},
88
88
  componentGenerics: ${JSON.stringify(componentGenerics)},
89
89
  genericsInfo: ${JSON.stringify(genericsInfo)},
@@ -13,6 +13,7 @@ module.exports = function (template, {
13
13
  moduleId,
14
14
  ctorType,
15
15
  usingComponentsInfo,
16
+ originalUsingComponents,
16
17
  componentGenerics
17
18
  }, callback) {
18
19
  const mpx = loaderContext.getMpx()
@@ -51,10 +52,10 @@ module.exports = function (template, {
51
52
  if (template) {
52
53
  // 由于远端src template资源引用的相对路径可能发生变化,暂时不支持。
53
54
  if (template.src) {
54
- return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template content must be inline in .mpx files!'))
55
+ return callback(new Error('[Mpx template error][' + loaderContext.resource + ']: ' + 'template content must be inline in .mpx files!'))
55
56
  }
56
57
  if (template.lang) {
57
- return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template lang is not supported in trans web mode temporarily, we will support it in the future!'))
58
+ return callback(new Error('[Mpx template error][' + loaderContext.resource + ']: ' + 'template lang is not supported in trans web mode temporarily, we will support it in the future!'))
58
59
  }
59
60
 
60
61
  output += genComponentTag(template, (template) => {
@@ -65,18 +66,19 @@ module.exports = function (template, {
65
66
  const templateSrcMode = template.mode || srcMode
66
67
  const warn = (msg) => {
67
68
  loaderContext.emitWarning(
68
- new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
69
+ new Error('[Mpx template error][' + loaderContext.resource + ']: ' + msg)
69
70
  )
70
71
  }
71
72
  const error = (msg) => {
72
73
  loaderContext.emitError(
73
- new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
74
+ new Error('[Mpx template error][' + loaderContext.resource + ']: ' + msg)
74
75
  )
75
76
  }
76
77
  const { root, meta } = templateCompiler.parse(template.content, {
77
78
  warn,
78
79
  error,
79
80
  usingComponentsInfo, // processTemplate中无其他地方使用,直接透传 string 类型
81
+ originalUsingComponents,
80
82
  hasComment,
81
83
  isNative,
82
84
  ctorType,
@@ -24,19 +24,29 @@ function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderC
24
24
  Object.keys(localComponentsMap).forEach((componentName) => {
25
25
  const componentCfg = localComponentsMap[componentName]
26
26
  const componentRequest = stringifyRequest(loaderContext, componentCfg.resource)
27
+
27
28
  if (componentCfg.async) {
28
- // todo 暂时只处理局部注册的组件作为componentPlaceholder,暂不支持全局组件和原生组件,如使用了支持范围外的组件将不进行placeholder渲染及替换
29
- if (jsonConfig.componentPlaceholder && jsonConfig.componentPlaceholder[componentName] && localComponentsMap[jsonConfig.componentPlaceholder[componentName]]) {
30
- const placeholder = jsonConfig.componentPlaceholder[componentName]
29
+ const placeholder = jsonConfig.componentPlaceholder && jsonConfig.componentPlaceholder[componentName]
30
+ if (placeholder) {
31
31
  const placeholderCfg = localComponentsMap[placeholder]
32
- const placeholderRequest = stringifyRequest(loaderContext, placeholderCfg.resource)
33
- if (placeholderCfg.async) {
34
- loaderContext.emitWarning(
35
- new Error(`[json processor][${loaderContext.resource}]: componentPlaceholder ${placeholder} should not be a async component, please check!`)
32
+ if (placeholderCfg) {
33
+ if (placeholderCfg.async) {
34
+ loaderContext.emitWarning(
35
+ new Error(`[Mpx json error][${loaderContext.resource}]: componentPlaceholder ${placeholder} should not be a async component, please check!`)
36
+ )
37
+ }
38
+ const placeholderRequest = stringifyRequest(loaderContext, placeholderCfg.resource)
39
+ componentsMap[componentName] = `function(){return {component: import(${getAsyncChunkName(componentCfg.async)}${componentRequest}).then(function(res){return getComponent(res)}), loading: getComponent(require(${placeholderRequest}))}}`
40
+ } else {
41
+ loaderContext.emitError(
42
+ new Error(`[json processor][${loaderContext.resource}]: componentPlaceholder ${placeholder} is not built-in component or custom component, please check!`)
36
43
  )
44
+ componentsMap[componentName] = `function(){return import(${getAsyncChunkName(componentCfg.async)}${componentRequest}).then(function(res){return getComponent(res)})}`
37
45
  }
38
- componentsMap[componentName] = `function(){return {component: import(${getAsyncChunkName(componentCfg.async)}${componentRequest}).then(function(res){return getComponent(res)}), loading: getComponent(require(${placeholderRequest}))}}`
39
46
  } else {
47
+ loaderContext.emitError(
48
+ new Error(`[json processor][${loaderContext.resource}]: ${componentName} has no componentPlaceholder, please check!`)
49
+ )
40
50
  componentsMap[componentName] = `function(){return import(${getAsyncChunkName(componentCfg.async)}${componentRequest}).then(function(res){return getComponent(res)})}`
41
51
  }
42
52
  } else {
@@ -75,7 +85,7 @@ function buildPagesMap ({ localPagesMap, loaderContext, tabBar, tabBarMap, tabBa
75
85
  }
76
86
  } else {
77
87
  loaderContext.emitWarning(
78
- new Error(`[json processor][${loaderContext.resource}]: TabBar page path ${pagePath} is not exist in local page map, please check!`)
88
+ new Error(`[Mpx json error][${loaderContext.resource}]: TabBar page path ${pagePath} is not exist in local page map, please check!`)
79
89
  )
80
90
  }
81
91
  })
@@ -4,7 +4,7 @@ const t = require('@babel/types')
4
4
  const generate = require('@babel/generator').default
5
5
  const parseRequest = require('../utils/parse-request')
6
6
  const isEmptyObject = require('../utils/is-empty-object')
7
- const chainAssign = require('../utils/chain-assign')
7
+ const mergeVisitors = require('../utils/merge-visitors')
8
8
  const parseQuery = require('loader-utils').parseQuery
9
9
 
10
10
  module.exports = function (content) {
@@ -31,7 +31,7 @@ module.exports = function (content) {
31
31
  ' __mpx_args__[i] = arguments[i];\n' +
32
32
  '}'
33
33
  ).program.body
34
- chainAssign(visitor, {
34
+ mergeVisitors(visitor, {
35
35
  Identifier (path) {
36
36
  if (path.node.name === 'arguments') {
37
37
  path.node.name = '__mpx_args__'
@@ -66,7 +66,7 @@ module.exports = function (content) {
66
66
  }
67
67
 
68
68
  if (mode !== 'wx') {
69
- chainAssign(visitor, {
69
+ mergeVisitors(visitor, {
70
70
  CallExpression (path) {
71
71
  const callee = path.node.callee
72
72
  if (t.isIdentifier(callee) && callee.name === 'getRegExp') {
@@ -81,7 +81,7 @@ module.exports = function (content) {
81
81
  }
82
82
 
83
83
  if (mode === 'dd') {
84
- chainAssign(visitor, {
84
+ mergeVisitors(visitor, {
85
85
  MemberExpression (path) {
86
86
  const property = path.node.property
87
87
  if (
@@ -96,11 +96,14 @@ module.exports = function (content) {
96
96
  }
97
97
 
98
98
  if (!module.wxs) {
99
- chainAssign(visitor, {
99
+ mergeVisitors(visitor, {
100
100
  MemberExpression (path) {
101
+ if (!t.isMemberExpression(path.node)) {
102
+ return
103
+ }
101
104
  const property = path.node.property
102
105
  if (
103
- (property.name === 'constructor' || property.value === 'constructor') &&
106
+ property && (property.name === 'constructor' || property.value === 'constructor') &&
104
107
  !(t.isMemberExpression(path.parent) && path.parentKey === 'object')
105
108
  ) {
106
109
  path.replaceWith(t.memberExpression(path.node, t.identifier('name')))
@@ -32,13 +32,6 @@ const {
32
32
  } = require('./utils')
33
33
  const createHelpers = require('../helpers')
34
34
 
35
- const RN_PRESET_OPTIMISATION = {
36
- reduceInitial: false,
37
- normalizeWhitespace: false,
38
- minifyFontValues: false,
39
- convertValues: false
40
- }
41
-
42
35
  module.exports = async function loader (content, map, meta) {
43
36
  const rawOptions = this.getOptions(schema)
44
37
  const plugins = []
@@ -157,12 +150,11 @@ module.exports = async function loader (content, map, meta) {
157
150
  )
158
151
  }
159
152
 
160
- if (this.minimize) {
153
+ if (this.minimize && !isRN) {
161
154
  const cssnano = require('cssnano')
162
155
  const minimizeOptions = rawOptions.minimize || {}
163
156
  const presetOptimisation = Object.assign(
164
157
  {},
165
- isRN ? RN_PRESET_OPTIMISATION : {},
166
158
  minimizeOptions.optimisation
167
159
  )
168
160
  let cssnanoConfig = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.16",
3
+ "version": "2.10.17-beta.10",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -29,7 +29,7 @@
29
29
  "@better-scroll/wheel": "^2.5.1",
30
30
  "@better-scroll/zoom": "^2.5.1",
31
31
  "@mpxjs/template-engine": "^2.8.7",
32
- "@mpxjs/utils": "^2.10.16",
32
+ "@mpxjs/utils": "^2.10.17",
33
33
  "acorn": "^8.11.3",
34
34
  "acorn-walk": "^7.2.0",
35
35
  "async": "^2.6.0",
@@ -78,16 +78,18 @@
78
78
  "url": "https://github.com/didi/mpx/issues"
79
79
  },
80
80
  "scripts": {
81
- "test": "jest",
81
+ "test": "jest --passWithNoTests",
82
82
  "copy-icons": "cp -r ./lib/runtime/components/react/mpx-icon/icons ./lib/runtime/components/react/dist/mpx-icon/icons",
83
- "build": "rimraf ./lib/runtime/components/react/dist && tsc && npm run copy-icons"
83
+ "build": "rimraf ./lib/runtime/components/react/dist && tsc -p ./lib/runtime/components/react/tsconfig.json && npm run copy-icons"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@d11/react-native-fast-image": "^8.6.12",
87
- "@mpxjs/api-proxy": "^2.10.16",
87
+ "@mpxjs/api-proxy": "^2.10.17-beta.0",
88
88
  "@types/babel-traverse": "^6.25.4",
89
89
  "@types/babel-types": "^7.0.4",
90
+ "@types/glob": "^8.1.0",
90
91
  "@types/react": "^18.2.79",
92
+ "glob": "^11.0.2",
91
93
  "react-native": "^0.74.5",
92
94
  "react-native-gesture-handler": "^2.18.1",
93
95
  "react-native-linear-gradient": "^2.8.3",
@@ -95,11 +97,13 @@
95
97
  "react-native-safe-area-context": "^4.12.0",
96
98
  "react-native-svg": "^15.8.0",
97
99
  "react-native-video": "^6.9.0",
100
+ "react-native-vision-camera": "^4.7.2",
98
101
  "react-native-webview": "^13.12.2",
99
- "rimraf": "^6.0.1"
102
+ "rimraf": "^6.0.1",
103
+ "webpack": "^5.75.0"
100
104
  },
101
105
  "engines": {
102
106
  "node": ">=14.14.0"
103
107
  },
104
- "gitHead": "be4129320e298edf935ea35f9ca3d375f75ac51c"
108
+ "gitHead": "2d37697869b9bdda3efab92dda8c910b68fd05c0"
105
109
  }