@mpxjs/webpack-plugin 2.10.16 → 2.10.17

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/dependencies/AppEntryDependency.js +2 -2
  2. package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
  3. package/lib/dependencies/ResolveDependency.js +1 -1
  4. package/lib/helpers.js +2 -0
  5. package/lib/index.js +40 -15
  6. package/lib/json-compiler/helper.js +72 -2
  7. package/lib/json-compiler/index.js +14 -54
  8. package/lib/json-compiler/plugin.js +2 -2
  9. package/lib/loader.js +10 -4
  10. package/lib/native-loader.js +6 -3
  11. package/lib/platform/json/wx/index.js +24 -29
  12. package/lib/platform/style/wx/index.js +8 -1
  13. package/lib/platform/template/wx/component-config/button.js +12 -3
  14. package/lib/platform/template/wx/component-config/component.js +31 -33
  15. package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
  16. package/lib/react/index.js +2 -0
  17. package/lib/react/processJSON.js +39 -71
  18. package/lib/react/processStyles.js +3 -2
  19. package/lib/react/processTemplate.js +8 -6
  20. package/lib/react/script-helper.js +6 -16
  21. package/lib/react/style-helper.js +10 -2
  22. package/lib/runtime/components/react/context.ts +12 -6
  23. package/lib/runtime/components/react/dist/context.d.ts +75 -0
  24. package/lib/runtime/components/react/dist/context.d.ts.map +1 -0
  25. package/lib/runtime/components/react/dist/context.js +1 -0
  26. package/lib/runtime/components/react/dist/event.config.d.ts +8 -0
  27. package/lib/runtime/components/react/dist/event.config.d.ts.map +1 -0
  28. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +8 -0
  29. package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +1 -0
  30. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +13 -0
  31. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +1 -0
  32. package/lib/runtime/components/react/dist/mpx-button.d.ts +69 -0
  33. package/lib/runtime/components/react/dist/mpx-button.d.ts.map +1 -0
  34. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +24 -0
  35. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +1 -0
  36. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +8 -0
  37. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +1 -0
  38. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +7 -0
  39. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +1 -0
  40. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +21 -0
  41. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +1 -0
  42. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +9 -0
  43. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +1 -0
  44. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +11 -0
  45. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +1 -0
  46. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +3 -0
  47. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +1 -0
  48. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +33 -0
  49. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +1 -0
  50. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
  51. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +53 -0
  52. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +1 -0
  53. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +21 -0
  54. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +1 -0
  55. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +33 -0
  56. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +1 -0
  57. package/lib/runtime/components/react/dist/mpx-form.d.ts +28 -0
  58. package/lib/runtime/components/react/dist/mpx-form.d.ts.map +1 -0
  59. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +19 -0
  60. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +1 -0
  61. package/lib/runtime/components/react/dist/mpx-image.d.ts +22 -0
  62. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +1 -0
  63. package/lib/runtime/components/react/dist/mpx-image.jsx +107 -57
  64. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +8 -0
  65. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +1 -0
  66. package/lib/runtime/components/react/dist/mpx-input.d.ts +50 -0
  67. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -0
  68. package/lib/runtime/components/react/dist/mpx-input.jsx +32 -8
  69. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +13 -0
  70. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +1 -0
  71. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +58 -50
  72. package/lib/runtime/components/react/dist/mpx-label.d.ts +21 -0
  73. package/lib/runtime/components/react/dist/mpx-label.d.ts.map +1 -0
  74. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +21 -0
  75. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +1 -0
  76. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +66 -0
  77. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +1 -0
  78. package/lib/runtime/components/react/dist/mpx-nav.d.ts +9 -0
  79. package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +1 -0
  80. package/lib/runtime/components/react/dist/mpx-nav.jsx +132 -0
  81. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +10 -0
  82. package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +1 -0
  83. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +7 -0
  84. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +1 -0
  85. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +8 -0
  86. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +1 -0
  87. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +7 -0
  88. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +1 -0
  89. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +7 -0
  90. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +1 -0
  91. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +7 -0
  92. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +1 -0
  93. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +3 -0
  94. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +1 -0
  95. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +7 -0
  96. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +1 -0
  97. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +7 -0
  98. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +1 -0
  99. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +107 -0
  100. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +1 -0
  101. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +33 -0
  102. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +1 -0
  103. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +4 -3
  104. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +9 -0
  105. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +1 -0
  106. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +24 -0
  107. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +1 -0
  108. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +12 -18
  109. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +15 -0
  110. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +1 -0
  111. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +8 -11
  112. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +14 -0
  113. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +1 -0
  114. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +20 -0
  115. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +17 -0
  116. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +1 -0
  117. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +13 -0
  118. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +1 -0
  119. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +12 -0
  120. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +1 -0
  121. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +23 -0
  122. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +1 -0
  123. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +17 -0
  124. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +1 -0
  125. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +16 -0
  126. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +1 -0
  127. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
  128. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +30 -0
  129. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +1 -0
  130. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +10 -0
  131. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +1 -0
  132. package/lib/runtime/components/react/dist/mpx-progress.d.ts +24 -0
  133. package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +1 -0
  134. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +21 -0
  135. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +1 -0
  136. package/lib/runtime/components/react/dist/mpx-radio.d.ts +27 -0
  137. package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +1 -0
  138. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +2 -0
  139. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +1 -0
  140. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +25 -0
  141. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +1 -0
  142. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -1
  143. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +15 -0
  144. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +1 -0
  145. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +55 -0
  146. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +1 -0
  147. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
  148. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +8 -0
  149. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +1 -0
  150. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +8 -0
  151. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +1 -0
  152. package/lib/runtime/components/react/dist/mpx-slider.d.ts +31 -0
  153. package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +1 -0
  154. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +18 -0
  155. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +1 -0
  156. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +16 -0
  157. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +1 -0
  158. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +19 -0
  159. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +1 -0
  160. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +53 -0
  161. package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +1 -0
  162. package/lib/runtime/components/react/dist/mpx-switch.d.ts +27 -0
  163. package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +1 -0
  164. package/lib/runtime/components/react/dist/mpx-text.d.ts +23 -0
  165. package/lib/runtime/components/react/dist/mpx-text.d.ts.map +1 -0
  166. package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
  167. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +8 -0
  168. package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +1 -0
  169. package/lib/runtime/components/react/dist/mpx-video.d.ts +102 -0
  170. package/lib/runtime/components/react/dist/mpx-video.d.ts.map +1 -0
  171. package/lib/runtime/components/react/dist/mpx-view.d.ts +35 -0
  172. package/lib/runtime/components/react/dist/mpx-view.d.ts.map +1 -0
  173. package/lib/runtime/components/react/dist/mpx-view.jsx +1 -1
  174. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +23 -0
  175. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +1 -0
  176. package/lib/runtime/components/react/dist/mpx-web-view.jsx +10 -2
  177. package/lib/runtime/components/react/dist/parser.d.ts +40 -0
  178. package/lib/runtime/components/react/dist/parser.d.ts.map +1 -0
  179. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +33 -0
  180. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +1 -0
  181. package/lib/runtime/components/react/dist/useNodesRef.d.ts +12 -0
  182. package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +1 -0
  183. package/lib/runtime/components/react/dist/utils.d.ts +123 -0
  184. package/lib/runtime/components/react/dist/utils.d.ts.map +1 -0
  185. package/lib/runtime/components/react/dist/utils.jsx +16 -6
  186. package/lib/runtime/components/react/mpx-canvas/index.tsx +1 -1
  187. package/lib/runtime/components/react/mpx-image.tsx +130 -77
  188. package/lib/runtime/components/react/mpx-input.tsx +38 -15
  189. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +66 -49
  190. package/lib/runtime/components/react/mpx-nav.tsx +155 -0
  191. package/lib/runtime/components/react/mpx-picker-view/index.tsx +5 -2
  192. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +26 -21
  193. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +8 -12
  194. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +55 -0
  195. package/lib/runtime/components/react/mpx-portal/index.tsx +8 -2
  196. package/lib/runtime/components/react/mpx-rich-text/index.tsx +1 -1
  197. package/lib/runtime/components/react/mpx-scroll-view.tsx +6 -17
  198. package/lib/runtime/components/react/mpx-text.tsx +38 -5
  199. package/lib/runtime/components/react/mpx-view.tsx +1 -1
  200. package/lib/runtime/components/react/mpx-web-view.tsx +13 -4
  201. package/lib/runtime/components/react/types/common.d.ts +19 -0
  202. package/lib/runtime/components/react/utils.tsx +15 -6
  203. package/lib/script-setup-compiler/index.js +2 -2
  204. package/lib/style-compiler/index.js +3 -2
  205. package/lib/style-compiler/load-postcss-config.js +1 -1
  206. package/lib/style-compiler/plugins/trans-special.js +10 -2
  207. package/lib/style-compiler/strip-conditional-loader.js +177 -15
  208. package/lib/template-compiler/compiler.js +268 -70
  209. package/lib/template-compiler/gen-node-react.js +18 -6
  210. package/lib/template-compiler/index.js +6 -4
  211. package/lib/template-compiler/parse-exps.js +1 -1
  212. package/lib/utils/const.js +2 -1
  213. package/lib/utils/dom-tag-config.js +5 -5
  214. package/lib/utils/env.js +6 -1
  215. package/lib/utils/get-build-tag-component.js +35 -0
  216. package/lib/utils/merge-visitors.js +55 -0
  217. package/lib/utils/pre-process-json.js +5 -0
  218. package/lib/web/index.js +2 -0
  219. package/lib/web/processJSON.js +44 -16
  220. package/lib/web/processScript.js +1 -1
  221. package/lib/web/processTemplate.js +6 -4
  222. package/lib/web/script-helper.js +19 -9
  223. package/lib/wxs/pre-loader.js +9 -6
  224. package/lib/wxss/loader.js +1 -9
  225. package/package.json +15 -5
  226. package/lib/utils/chain-assign.js +0 -47
@@ -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)
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
  },
@@ -37,23 +37,38 @@ module.exports = function (jsonContent, {
37
37
 
38
38
  const emitWarning = (msg) => {
39
39
  loaderContext.emitWarning(
40
- new Error('[json processor][' + loaderContext.resource + ']: ' + msg)
40
+ new Error('[Mpx json warning][' + loaderContext.resource + ']: ' + msg)
41
41
  )
42
42
  }
43
43
 
44
44
  const emitError = (msg) => {
45
45
  loaderContext.emitError(
46
- new Error('[json compiler][' + loaderContext.resource + ']: ' + msg)
46
+ new Error('[Mpx json error][' + loaderContext.resource + ']: ' + msg)
47
47
  )
48
48
  }
49
49
 
50
50
  const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
51
51
 
52
+ function fillInComponentsMap (name, entry, tarRoot) {
53
+ const { resource, outputPath } = entry
54
+ const { resourcePath } = parseRequest(resource)
55
+ componentsMap[resourcePath] = outputPath
56
+ loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
57
+ localComponentsMap[name] = {
58
+ resource: addQuery(resource, {
59
+ isComponent: true,
60
+ outputPath
61
+ }),
62
+ async: tarRoot
63
+ }
64
+ }
65
+
52
66
  const {
53
67
  isUrlRequest,
54
68
  urlToRequest,
55
69
  processPage,
56
- processComponent
70
+ processComponent,
71
+ processPlaceholder
57
72
  } = createJSONHelper({
58
73
  loaderContext,
59
74
  emitWarning,
@@ -240,7 +255,7 @@ module.exports = function (jsonContent, {
240
255
  if (oldResourcePath !== resourcePath) {
241
256
  const oldOutputPath = outputPath
242
257
  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!`))
258
+ 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
259
  }
245
260
  }
246
261
 
@@ -287,22 +302,35 @@ module.exports = function (jsonContent, {
287
302
 
288
303
  const processComponents = (components, context, callback) => {
289
304
  if (components) {
305
+ const asyncComponents = []
306
+ const resolveResourcePathMap = new Map()
290
307
  async.eachOf(components, (component, name, callback) => {
291
- processComponent(component, context, {}, (err, { resource, outputPath } = {}, { tarRoot } = {}) => {
308
+ processComponent(component, context, {}, (err, entry = {}, { tarRoot, placeholder, resourcePath } = {}) => {
292
309
  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
- }
310
+ const { relativePath, resource } = entry
311
+ const { queryObj } = parseRequest(resource)
312
+
313
+ tarRoot = queryObj.async || tarRoot
314
+
315
+ resolveResourcePathMap.set(name, resourcePath)
316
+ if (tarRoot) asyncComponents.push({ name, tarRoot, placeholder, relativePath })
317
+
318
+ fillInComponentsMap(name, entry, tarRoot)
303
319
  callback()
304
320
  })
305
- }, callback)
321
+ }, (err) => {
322
+ if (err) return callback(err)
323
+ async.each(asyncComponents, ({ name, tarRoot, placeholder, relativePath }, callback) => {
324
+ processPlaceholder({ jsonObj, context, name, tarRoot, placeholder, relativePath, resolveResourcePathMap }, (err, placeholder) => {
325
+ if (err) return callback(err)
326
+ if (placeholder) {
327
+ const { name, entry } = placeholder
328
+ fillInComponentsMap(name, entry, '')
329
+ }
330
+ callback()
331
+ })
332
+ }, callback)
333
+ })
306
334
  } else {
307
335
  callback()
308
336
  }
@@ -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",
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",
@@ -51,18 +51,25 @@
51
51
  "mime": "^2.2.2",
52
52
  "object-assign": "^4.1.1",
53
53
  "postcss": "^8.4.5",
54
+ "postcss-import": "^16.1.1",
55
+ "postcss-less": "^6.0.0",
54
56
  "postcss-load-config": "^3.1.1",
55
57
  "postcss-modules-extract-imports": "^3.0.0",
56
58
  "postcss-modules-local-by-default": "^4.0.0",
57
59
  "postcss-modules-scope": "^3.0.0",
58
60
  "postcss-modules-values": "^4.0.0",
61
+ "postcss-scss": "^4.0.9",
59
62
  "postcss-selector-parser": "^6.0.8",
63
+ "postcss-styl": "^0.12.3",
60
64
  "postcss-value-parser": "^4.0.2",
61
65
  "semver": "^7.5.4",
62
66
  "source-list-map": "^2.0.0",
63
67
  "webpack-virtual-modules": "^0.6.0"
64
68
  },
65
69
  "peerDependencies": {
70
+ "postcss-less": "^6.0.0",
71
+ "postcss-scss": "^4.0.9",
72
+ "postcss-styl": "^0.12.3",
66
73
  "webpack": "^5.75.0"
67
74
  },
68
75
  "publishConfig": {
@@ -78,16 +85,19 @@
78
85
  "url": "https://github.com/didi/mpx/issues"
79
86
  },
80
87
  "scripts": {
81
- "test": "jest",
88
+ "test": "jest --passWithNoTests",
82
89
  "copy-icons": "cp -r ./lib/runtime/components/react/mpx-icon/icons ./lib/runtime/components/react/dist/mpx-icon/icons",
83
90
  "build": "rimraf ./lib/runtime/components/react/dist && tsc && npm run copy-icons"
84
91
  },
85
92
  "devDependencies": {
86
93
  "@d11/react-native-fast-image": "^8.6.12",
87
- "@mpxjs/api-proxy": "^2.10.16",
94
+ "@mpxjs/api-proxy": "^2.10.17",
88
95
  "@types/babel-traverse": "^6.25.4",
89
96
  "@types/babel-types": "^7.0.4",
97
+ "@types/glob": "^8.1.0",
98
+ "@types/postcss-import": "^14.0.3",
90
99
  "@types/react": "^18.2.79",
100
+ "glob": "^11.0.2",
91
101
  "react-native": "^0.74.5",
92
102
  "react-native-gesture-handler": "^2.18.1",
93
103
  "react-native-linear-gradient": "^2.8.3",
@@ -101,5 +111,5 @@
101
111
  "engines": {
102
112
  "node": ">=14.14.0"
103
113
  },
104
- "gitHead": "be4129320e298edf935ea35f9ca3d375f75ac51c"
114
+ "gitHead": "33fbd0bb8d4b83555239a8931fabb23022af0866"
105
115
  }
@@ -1,47 +0,0 @@
1
- /**
2
- * 链式合并方法的工具函数
3
- *
4
- * 在多条件分支下使用 Object.assign 会导致同名方法被覆盖,
5
- * 这个函数通过创建组合函数来确保所有方法都能按顺序执行。
6
- *
7
- * @param {Object} target - 目标 visitor 对象
8
- * @param {Object} source - 要链式分配的 visitor 方法对象
9
- *
10
- * @example
11
- * const visitor = {}
12
- *
13
- * // 第一次合并
14
- * chainAssign(visitor, {
15
- * CallExpression(path) {
16
- * console.log('第一个处理器')
17
- * }
18
- * })
19
- *
20
- * // 第二次合并 - 不会覆盖,而是组合执行
21
- * chainAssign(visitor, {
22
- * CallExpression(path) {
23
- * console.log('第二个处理器')
24
- * }
25
- * })
26
- *
27
- * // 执行时会依次输出:
28
- * // 第一个处理器
29
- * // 第二个处理器
30
- */
31
- module.exports = function chainAssign (target, source) {
32
- for (const [key, value] of Object.entries(source)) {
33
- if (target[key]) {
34
- // 如果已存在同名方法,创建组合函数依次执行
35
- const originalMethod = target[key]
36
- target[key] = function (path) {
37
- originalMethod.call(this, path)
38
- // 只有当节点没有停止遍历或被移除时才继续执行
39
- if (!path.removed && !path.shouldStop) {
40
- value.call(this, path)
41
- }
42
- }
43
- } else {
44
- target[key] = value
45
- }
46
- }
47
- }