@mpxjs/webpack-plugin 2.10.15 → 2.10.16-beta.11

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 (274) hide show
  1. package/lib/config.js +60 -0
  2. package/lib/dependencies/AppEntryDependency.js +2 -2
  3. package/lib/dependencies/DynamicEntryDependency.js +1 -1
  4. package/lib/dependencies/ImportDependency.js +102 -0
  5. package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
  6. package/lib/dependencies/ResolveDependency.js +1 -1
  7. package/lib/{retry-runtime-module.js → dependencies/RetryRuntimeModule.js} +1 -1
  8. package/lib/file-loader.js +13 -3
  9. package/lib/helpers.js +2 -0
  10. package/lib/index.js +51 -25
  11. package/lib/json-compiler/helper.js +72 -2
  12. package/lib/json-compiler/index.js +16 -56
  13. package/lib/json-compiler/plugin.js +2 -2
  14. package/lib/loader.js +10 -4
  15. package/lib/native-loader.js +6 -3
  16. package/lib/platform/json/wx/index.js +30 -29
  17. package/lib/platform/style/wx/index.js +8 -1
  18. package/lib/platform/template/wx/component-config/ad.js +5 -0
  19. package/lib/platform/template/wx/component-config/button.js +21 -5
  20. package/lib/platform/template/wx/component-config/camera.js +25 -3
  21. package/lib/platform/template/wx/component-config/canvas.js +8 -1
  22. package/lib/platform/template/wx/component-config/component.js +31 -33
  23. package/lib/platform/template/wx/component-config/cover-image.js +7 -2
  24. package/lib/platform/template/wx/component-config/cover-view.js +3 -1
  25. package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
  26. package/lib/platform/template/wx/component-config/form.js +27 -2
  27. package/lib/platform/template/wx/component-config/image.js +5 -0
  28. package/lib/platform/template/wx/component-config/input.js +10 -0
  29. package/lib/platform/template/wx/component-config/label.js +10 -2
  30. package/lib/platform/template/wx/component-config/map.js +11 -0
  31. package/lib/platform/template/wx/component-config/movable-area.js +4 -1
  32. package/lib/platform/template/wx/component-config/movable-view.js +17 -2
  33. package/lib/platform/template/wx/component-config/navigator.js +26 -0
  34. package/lib/platform/template/wx/component-config/picker-view.js +12 -0
  35. package/lib/platform/template/wx/component-config/picker.js +3 -1
  36. package/lib/platform/template/wx/component-config/progress.js +11 -1
  37. package/lib/platform/template/wx/component-config/rich-text.js +5 -0
  38. package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
  39. package/lib/platform/template/wx/component-config/slider.js +20 -0
  40. package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
  41. package/lib/platform/template/wx/component-config/swiper.js +10 -0
  42. package/lib/platform/template/wx/component-config/text.js +5 -0
  43. package/lib/platform/template/wx/component-config/textarea.js +19 -2
  44. package/lib/platform/template/wx/component-config/unsupported.js +10 -1
  45. package/lib/platform/template/wx/component-config/video.js +10 -0
  46. package/lib/platform/template/wx/index.js +21 -1
  47. package/lib/react/index.js +2 -0
  48. package/lib/react/processJSON.js +39 -71
  49. package/lib/react/processStyles.js +3 -2
  50. package/lib/react/processTemplate.js +8 -6
  51. package/lib/react/script-helper.js +6 -16
  52. package/lib/react/style-helper.js +10 -2
  53. package/lib/resolver/AddEnvPlugin.js +13 -0
  54. package/lib/resolver/AddModePlugin.js +18 -0
  55. package/lib/runtime/components/react/context.ts +13 -6
  56. package/lib/runtime/components/react/dist/context.d.ts +76 -0
  57. package/lib/runtime/components/react/dist/context.d.ts.map +1 -0
  58. package/lib/runtime/components/react/dist/context.js +1 -0
  59. package/lib/runtime/components/react/dist/event.config.d.ts +8 -0
  60. package/lib/runtime/components/react/dist/event.config.d.ts.map +1 -0
  61. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +8 -0
  62. package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +1 -0
  63. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +13 -0
  64. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +1 -0
  65. package/lib/runtime/components/react/dist/mpx-button.d.ts +69 -0
  66. package/lib/runtime/components/react/dist/mpx-button.d.ts.map +1 -0
  67. package/lib/runtime/components/react/dist/mpx-camera.d.ts +27 -0
  68. package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +1 -0
  69. package/lib/runtime/components/react/dist/mpx-camera.jsx +197 -0
  70. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +24 -0
  71. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +1 -0
  72. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +8 -0
  73. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +1 -0
  74. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +7 -0
  75. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +1 -0
  76. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +21 -0
  77. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +1 -0
  78. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +9 -0
  79. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +1 -0
  80. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +11 -0
  81. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +1 -0
  82. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +3 -0
  83. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +1 -0
  84. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +33 -0
  85. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +1 -0
  86. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +53 -0
  87. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +1 -0
  88. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +21 -0
  89. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +1 -0
  90. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +33 -0
  91. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +1 -0
  92. package/lib/runtime/components/react/dist/mpx-form.d.ts +28 -0
  93. package/lib/runtime/components/react/dist/mpx-form.d.ts.map +1 -0
  94. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +19 -0
  95. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +1 -0
  96. package/lib/runtime/components/react/dist/mpx-image.d.ts +22 -0
  97. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +1 -0
  98. package/lib/runtime/components/react/dist/mpx-image.jsx +81 -37
  99. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +8 -0
  100. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +1 -0
  101. package/lib/runtime/components/react/dist/mpx-input.d.ts +51 -0
  102. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -0
  103. package/lib/runtime/components/react/dist/mpx-input.jsx +40 -12
  104. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +13 -0
  105. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +1 -0
  106. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +61 -50
  107. package/lib/runtime/components/react/dist/mpx-label.d.ts +21 -0
  108. package/lib/runtime/components/react/dist/mpx-label.d.ts.map +1 -0
  109. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +21 -0
  110. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +1 -0
  111. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +66 -0
  112. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +1 -0
  113. package/lib/runtime/components/react/dist/mpx-nav.d.ts +9 -0
  114. package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +1 -0
  115. package/lib/runtime/components/react/dist/mpx-nav.jsx +132 -0
  116. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +10 -0
  117. package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +1 -0
  118. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +7 -0
  119. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +1 -0
  120. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +8 -0
  121. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +1 -0
  122. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +7 -0
  123. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +1 -0
  124. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +7 -0
  125. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +1 -0
  126. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +7 -0
  127. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +1 -0
  128. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +3 -0
  129. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +1 -0
  130. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +7 -0
  131. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +1 -0
  132. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +7 -0
  133. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +1 -0
  134. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +107 -0
  135. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +1 -0
  136. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +33 -0
  137. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +1 -0
  138. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +4 -3
  139. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +9 -0
  140. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +1 -0
  141. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +24 -0
  142. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +1 -0
  143. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +12 -18
  144. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +15 -0
  145. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +1 -0
  146. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +8 -11
  147. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +14 -0
  148. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +1 -0
  149. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +20 -0
  150. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +17 -0
  151. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +1 -0
  152. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +13 -0
  153. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +1 -0
  154. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +12 -0
  155. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +1 -0
  156. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +23 -0
  157. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +1 -0
  158. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +17 -0
  159. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +1 -0
  160. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +16 -0
  161. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +1 -0
  162. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
  163. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +30 -0
  164. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +1 -0
  165. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +10 -0
  166. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +1 -0
  167. package/lib/runtime/components/react/dist/mpx-progress.d.ts +24 -0
  168. package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +1 -0
  169. package/lib/runtime/components/react/dist/mpx-progress.jsx +26 -22
  170. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +21 -0
  171. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +1 -0
  172. package/lib/runtime/components/react/dist/mpx-radio.d.ts +27 -0
  173. package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +1 -0
  174. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +2 -0
  175. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +1 -0
  176. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +25 -0
  177. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +1 -0
  178. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +15 -0
  179. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +1 -0
  180. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +55 -0
  181. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +1 -0
  182. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
  183. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +8 -0
  184. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +1 -0
  185. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +8 -0
  186. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +1 -0
  187. package/lib/runtime/components/react/dist/mpx-slider.d.ts +31 -0
  188. package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +1 -0
  189. package/lib/runtime/components/react/dist/mpx-slider.jsx +321 -0
  190. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +18 -0
  191. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +1 -0
  192. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +16 -0
  193. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +1 -0
  194. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +19 -0
  195. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +1 -0
  196. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +53 -0
  197. package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +1 -0
  198. package/lib/runtime/components/react/dist/mpx-swiper.jsx +9 -5
  199. package/lib/runtime/components/react/dist/mpx-switch.d.ts +27 -0
  200. package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +1 -0
  201. package/lib/runtime/components/react/dist/mpx-text.d.ts +23 -0
  202. package/lib/runtime/components/react/dist/mpx-text.d.ts.map +1 -0
  203. package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
  204. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +8 -0
  205. package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +1 -0
  206. package/lib/runtime/components/react/dist/mpx-video.d.ts +102 -0
  207. package/lib/runtime/components/react/dist/mpx-video.d.ts.map +1 -0
  208. package/lib/runtime/components/react/dist/mpx-view.d.ts +35 -0
  209. package/lib/runtime/components/react/dist/mpx-view.d.ts.map +1 -0
  210. package/lib/runtime/components/react/dist/mpx-view.jsx +8 -11
  211. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +23 -0
  212. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +1 -0
  213. package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
  214. package/lib/runtime/components/react/dist/parser.d.ts +40 -0
  215. package/lib/runtime/components/react/dist/parser.d.ts.map +1 -0
  216. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +33 -0
  217. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +1 -0
  218. package/lib/runtime/components/react/dist/useNodesRef.d.ts +12 -0
  219. package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +1 -0
  220. package/lib/runtime/components/react/dist/utils.d.ts +123 -0
  221. package/lib/runtime/components/react/dist/utils.d.ts.map +1 -0
  222. package/lib/runtime/components/react/dist/utils.jsx +16 -6
  223. package/lib/runtime/components/react/mpx-camera.tsx +275 -0
  224. package/lib/runtime/components/react/mpx-image.tsx +89 -42
  225. package/lib/runtime/components/react/mpx-input.tsx +50 -18
  226. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +69 -49
  227. package/lib/runtime/components/react/mpx-nav.tsx +155 -0
  228. package/lib/runtime/components/react/mpx-picker-view/index.tsx +5 -2
  229. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +26 -21
  230. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +8 -12
  231. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +55 -0
  232. package/lib/runtime/components/react/mpx-portal/index.tsx +8 -2
  233. package/lib/runtime/components/react/mpx-progress.tsx +26 -24
  234. package/lib/runtime/components/react/mpx-scroll-view.tsx +6 -17
  235. package/lib/runtime/components/react/mpx-slider.tsx +444 -0
  236. package/lib/runtime/components/react/mpx-swiper.tsx +9 -5
  237. package/lib/runtime/components/react/mpx-text.tsx +38 -5
  238. package/lib/runtime/components/react/mpx-view.tsx +8 -11
  239. package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
  240. package/lib/runtime/components/react/types/common.d.ts +19 -0
  241. package/lib/runtime/components/react/utils.tsx +15 -6
  242. package/lib/runtime/components/web/mpx-input.vue +1 -1
  243. package/lib/runtime/components/web/mpx-scroll-view.vue +7 -1
  244. package/lib/runtime/components/web/mpx-video.vue +12 -1
  245. package/lib/runtime/optionProcessor.js +3 -1
  246. package/lib/runtime/optionProcessorReact.js +4 -2
  247. package/lib/runtime/stringify.wxs +2 -2
  248. package/lib/script-setup-compiler/index.js +2 -2
  249. package/lib/style-compiler/index.js +3 -2
  250. package/lib/style-compiler/load-postcss-config.js +1 -1
  251. package/lib/style-compiler/plugins/trans-special.js +10 -2
  252. package/lib/style-compiler/strip-conditional-loader.js +178 -15
  253. package/lib/template-compiler/bind-this.js +2 -2
  254. package/lib/template-compiler/compiler.js +277 -77
  255. package/lib/template-compiler/gen-node-react.js +18 -6
  256. package/lib/template-compiler/index.js +12 -10
  257. package/lib/template-compiler/parse-exps.js +1 -1
  258. package/lib/utils/chain-assign.js +47 -0
  259. package/lib/utils/check-core-version-match.js +75 -15
  260. package/lib/utils/const.js +2 -1
  261. package/lib/utils/dom-tag-config.js +6 -6
  262. package/lib/utils/env.js +6 -1
  263. package/lib/utils/get-build-tag-component.js +35 -0
  264. package/lib/utils/pre-process-json.js +5 -0
  265. package/lib/web/index.js +2 -0
  266. package/lib/web/processJSON.js +44 -16
  267. package/lib/web/processScript.js +1 -1
  268. package/lib/web/processTemplate.js +6 -4
  269. package/lib/web/script-helper.js +19 -9
  270. package/lib/wxs/pre-loader.js +6 -6
  271. package/lib/wxss/loader.js +1 -9
  272. package/package.json +17 -5
  273. package/LICENSE +0 -433
  274. package/lib/dependencies/ImportDependencyTemplate.js +0 -50
package/lib/config.js CHANGED
@@ -553,6 +553,66 @@ module.exports = {
553
553
  show: 'dd:show'
554
554
  }
555
555
  },
556
+ ks: {
557
+ typeExtMap: {
558
+ json: '.json',
559
+ script: '.js',
560
+ template: '.ksml',
561
+ styles: '.css'
562
+ },
563
+ tabBar: {
564
+ itemKey: 'list',
565
+ iconKey: 'iconPath',
566
+ activeIconKey: 'selectedIconPath'
567
+ },
568
+ event: {
569
+ parseEvent (attr) {
570
+ const match = /^(bind|catch|capture-bind|capture-catch):?(.*?)(?:\.(.*))?$/.exec(attr)
571
+ if (match) {
572
+ return {
573
+ prefix: match[1],
574
+ eventName: match[2],
575
+ modifier: match[3]
576
+ }
577
+ }
578
+ },
579
+ getEvent (eventName, prefix = 'bind') {
580
+ if (eventName.includes('-')) {
581
+ return `${prefix}:${eventName}`
582
+ } else {
583
+ return prefix + eventName
584
+ }
585
+ },
586
+ defaultModelProp: 'value',
587
+ defaultModelEvent: 'input',
588
+ defaultModelValuePath: 'value'
589
+ },
590
+ wxs: {
591
+ tag: 'ks',
592
+ module: 'module',
593
+ src: 'src',
594
+ ext: '.ks',
595
+ templatePrefix: 'module.exports = \n'
596
+ },
597
+ directive: {
598
+ if: 'ks:if',
599
+ elseif: 'ks:elif',
600
+ else: 'ks:else',
601
+ for: 'ks:for',
602
+ forIndex: 'ks:for-index',
603
+ forItem: 'ks:for-item',
604
+ key: 'ks:key',
605
+ dynamicClass: 'ks:class',
606
+ dynamicStyle: 'ks:style',
607
+ ref: 'ks:ref',
608
+ show: 'ks:show',
609
+ model: 'ks:model',
610
+ modelProp: 'ks:model-prop',
611
+ modelEvent: 'ks:model-event',
612
+ modelValuePath: 'ks:model-value-path',
613
+ modelFilter: 'ks:model-filter'
614
+ }
615
+ },
556
616
  ios: reactConfig,
557
617
  android: reactConfig,
558
618
  harmony: reactConfig
@@ -21,8 +21,8 @@ class AppEntryDependency extends NullDependency {
21
21
  if (mpx.appInfo.name) {
22
22
  const issuer = moduleGraph.getIssuer(module)
23
23
  const err = new Error(issuer
24
- ? `[json compiler]:Mpx单次构建中只能存在一个App,当前组件/页面[${module.resource}]通过[${issuer.resource}]非法引入,引用的资源将被忽略,请确保组件/页面资源通过usingComponents/pages配置引入!`
25
- : `[json compiler]:Mpx单次构建中只能存在一个App,请检查当前entry中的资源[${module.resource}]是否为组件/页面,通过添加?component/page查询字符串显式声明该资源是组件/页面!`)
24
+ ? `[Mpx json error]:Mpx单次构建中只能存在一个App,当前组件/页面[${module.resource}]通过[${issuer.resource}]非法引入,引用的资源将被忽略,请确保组件/页面资源通过usingComponents/pages配置引入!`
25
+ : `[Mpx json error]:Mpx单次构建中只能存在一个App,请检查当前entry中的资源[${module.resource}]是否为组件/页面,通过添加?component/page查询字符串显式声明该资源是组件/页面!`)
26
26
  return callback(err)
27
27
  }
28
28
 
@@ -6,7 +6,7 @@ const toPosix = require('../utils/to-posix')
6
6
  const async = require('async')
7
7
  const parseRequest = require('../utils/parse-request')
8
8
  const hasOwn = require('../utils/has-own')
9
- const { RetryRuntimeGlobal } = require('../retry-runtime-module')
9
+ const { RetryRuntimeGlobal } = require('./RetryRuntimeModule')
10
10
 
11
11
  class DynamicEntryDependency extends NullDependency {
12
12
  constructor (range, request, entryType, outputPath = '', packageRoot = '', relativePath = '', context = '', extraOptions = {}) {
@@ -0,0 +1,102 @@
1
+ const Dependency = require('webpack/lib/Dependency')
2
+ const makeSerializable = require('webpack/lib/util/makeSerializable')
3
+ const ModuleDependency = require('webpack/lib/dependencies/ModuleDependency')
4
+ const { RetryRuntimeGlobal } = require('./RetryRuntimeModule')
5
+
6
+ class ImportDependency extends ModuleDependency {
7
+ /**
8
+ * @param {string} request the request
9
+ * @param {[number, number]} range expression range
10
+ * @param {string[][]=} referencedExports list of referenced exports
11
+ */
12
+ constructor (request, range, referencedExports, extraOptions) {
13
+ super(request)
14
+ this.range = range
15
+ this.referencedExports = referencedExports
16
+ this.extraOptions = extraOptions
17
+ }
18
+
19
+ get type () {
20
+ return 'import()'
21
+ }
22
+
23
+ get category () {
24
+ return 'esm'
25
+ }
26
+
27
+ /**
28
+ * Returns list of exports referenced by this dependency
29
+ * @param {ModuleGraph} moduleGraph module graph
30
+ * @param {RuntimeSpec} runtime the runtime for which the module is analysed
31
+ * @returns {(string[] | ReferencedExport)[]} referenced exports
32
+ */
33
+ getReferencedExports (moduleGraph, runtime) {
34
+ return this.referencedExports
35
+ ? this.referencedExports.map((e) => ({
36
+ name: e,
37
+ canMangle: false
38
+ }))
39
+ : Dependency.EXPORTS_OBJECT_REFERENCED
40
+ }
41
+
42
+ serialize (context) {
43
+ context.write(this.range)
44
+ context.write(this.referencedExports)
45
+ context.write(this.extraOptions)
46
+ super.serialize(context)
47
+ }
48
+
49
+ deserialize (context) {
50
+ this.range = context.read()
51
+ this.referencedExports = context.read()
52
+ this.extraOptions = context.read()
53
+ super.deserialize(context)
54
+ }
55
+ }
56
+
57
+ makeSerializable(ImportDependency, '@mpxjs/webpack-plugin/lib/dependencies/ImportDependency')
58
+
59
+ ImportDependency.Template = class ImportDependencyTemplate extends (
60
+ ModuleDependency.Template
61
+ ) {
62
+ /**
63
+ * @param {Dependency} dependency the dependency for which the template should be applied
64
+ * @param {ReplaceSource} source the current replace source which can be modified
65
+ * @param {DependencyTemplateContext} templateContext the context object
66
+ * @returns {void}
67
+ */
68
+ apply (
69
+ dependency,
70
+ source,
71
+ { runtimeTemplate, module, moduleGraph, chunkGraph, runtimeRequirements }
72
+ ) {
73
+ const dep = /** @type {ImportDependency} */ (dependency)
74
+ const block = /** @type {AsyncDependenciesBlock} */ (
75
+ moduleGraph.getParentBlock(dep)
76
+ )
77
+ let content = runtimeTemplate.moduleNamespacePromise({
78
+ chunkGraph,
79
+ block: block,
80
+ module: /** @type {Module} */ (moduleGraph.getModule(dep)),
81
+ request: dep.request,
82
+ strict: /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule,
83
+ message: 'import()',
84
+ runtimeRequirements
85
+ })
86
+ // replace fakeType by 9 to fix require.async to commonjs2 module like 'module.exports = function(){...}'
87
+ content = content.replace(/(__webpack_require__\.t\.bind\(.+,\s*)(\d+)(\s*\))/, (_, p1, p2, p3) => {
88
+ return p1 + '9' + p3
89
+ })
90
+
91
+ // require.async 的场景且配置了重试次数才注入 RetryRuntimeModule
92
+ const extraOptions = dep.extraOptions || {}
93
+ if (extraOptions.isRequireAsync && extraOptions.retryRequireAsync && extraOptions.retryRequireAsync.times > 0) {
94
+ runtimeRequirements.add(RetryRuntimeGlobal)
95
+ content = `${RetryRuntimeGlobal}(function() { return ${content} }, ${extraOptions.retryRequireAsync.times}, ${extraOptions.retryRequireAsync.interval})`
96
+ }
97
+
98
+ source.replace(dep.range[0], dep.range[1] - 1, content)
99
+ }
100
+ }
101
+
102
+ module.exports = ImportDependency
@@ -0,0 +1,49 @@
1
+ const NullDependency = require('webpack/lib/dependencies/NullDependency')
2
+ const makeSerializable = require('webpack/lib/util/makeSerializable')
3
+
4
+ class RecordModuleIdMapDependency extends NullDependency {
5
+ constructor (moduleId, filePath) {
6
+ super()
7
+ this.moduleId = moduleId
8
+ this.filePath = filePath
9
+ }
10
+
11
+ get type () {
12
+ return 'mpx record module id map'
13
+ }
14
+
15
+ mpxAction (module, compilation, callback) {
16
+ const mpx = compilation.__mpx__
17
+ const { moduleId, filePath } = this
18
+ // 确保 resourceModuleIdMap 存在
19
+ if (!mpx.resourceModuleIdMap) {
20
+ mpx.resourceModuleIdMap = {}
21
+ }
22
+ // 记录 moduleId 和 filePath 的映射关系
23
+ mpx.resourceModuleIdMap[moduleId] = filePath
24
+ return callback()
25
+ }
26
+
27
+ serialize (context) {
28
+ const { write } = context
29
+ write(this.moduleId)
30
+ write(this.filePath)
31
+ super.serialize(context)
32
+ }
33
+
34
+ deserialize (context) {
35
+ const { read } = context
36
+ this.moduleId = read()
37
+ this.filePath = read()
38
+ super.deserialize(context)
39
+ }
40
+ }
41
+
42
+ RecordModuleIdMapDependency.Template = class RecordModuleIdMapDependencyTemplate {
43
+ apply () {
44
+ }
45
+ }
46
+
47
+ makeSerializable(RecordModuleIdMapDependency, '@mpxjs/webpack-plugin/lib/dependencies/RecordModuleIdMapDependency')
48
+
49
+ module.exports = RecordModuleIdMapDependency
@@ -36,7 +36,7 @@ class ResolveDependency extends NullDependency {
36
36
  const resolveResult = pagesMap[resourcePath] || currentComponentsMap[resourcePath] || mainComponentsMap[resourcePath] || currentStaticResourcesMap[resourcePath] || mainStaticResourcesMap[resourcePath] || ''
37
37
  if (!resolveResult) {
38
38
  if (!partialCompileRules || matchCondition(resourcePath, partialCompileRules)) {
39
- compilation.errors.push(new Error(`Path ${resource} is not a page/component/static resource, which is resolved from ${issuerResource}!`))
39
+ compilation.errors.push(new Error(`[Mpx json error]:Path ${resource} is not a page/component/static resource, which is resolved from ${issuerResource}!`))
40
40
  }
41
41
  }
42
42
  return resolveResult
@@ -1,7 +1,7 @@
1
1
  const Template = require('webpack/lib/Template')
2
2
  const RuntimeModule = require('webpack/lib/RuntimeModule')
3
3
 
4
- const RetryRuntimeGlobal = '__webpack_require__.__retry'
4
+ const RetryRuntimeGlobal = '__webpack_require__.mpxR'
5
5
 
6
6
  class RetryRuntimeModule extends RuntimeModule {
7
7
  constructor () {
@@ -8,7 +8,9 @@ module.exports = function loader (content, prevOptions) {
8
8
  const options = prevOptions || loaderUtils.getOptions(this) || {}
9
9
  const context = options.context || this.rootContext
10
10
  const mpx = this.getMpx()
11
- const isRN = ['ios', 'android', 'harmony'].includes(mpx.mode)
11
+
12
+ const { mode } = mpx
13
+ const isRN = ['ios', 'android', 'harmony'].includes(mode)
12
14
 
13
15
  let url = loaderUtils.interpolateName(this, options.name, {
14
16
  context,
@@ -17,6 +19,7 @@ module.exports = function loader (content, prevOptions) {
17
19
  })
18
20
 
19
21
  let outputPath = url
22
+ const { resourcePath, queryObj } = parseRequest(this.resource)
20
23
 
21
24
  if (options.publicPath) {
22
25
  if (options.outputPathCDN) {
@@ -27,13 +30,19 @@ module.exports = function loader (content, prevOptions) {
27
30
  }
28
31
  }
29
32
  } else {
30
- const { resourcePath, queryObj } = parseRequest(this.resource)
31
33
  const packageRoot = queryObj.packageRoot || ''
32
34
  url = outputPath = toPosix(path.join(packageRoot, outputPath))
33
35
  this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'staticResource', outputPath, packageRoot))
34
36
  }
35
37
 
36
- let publicPath = `__webpack_public_path__ + ${JSON.stringify(url)}`
38
+ let publicPath
39
+
40
+ // 快手小程序 tabbar icon 资源路径不能以 / 开头
41
+ if (queryObj.from === 'tabbar' && mode === 'ks') {
42
+ publicPath = JSON.stringify(url)
43
+ } else {
44
+ publicPath = `__webpack_public_path__ + ${JSON.stringify(url)}`
45
+ }
37
46
 
38
47
  if (isRN) {
39
48
  publicPath = `__mpx_require_external__(${JSON.stringify(url)})`
@@ -47,6 +56,7 @@ module.exports = function loader (content, prevOptions) {
47
56
  ? options.publicPath
48
57
  : `${options.publicPath}/`}${url}`
49
58
  }
59
+
50
60
  publicPath = JSON.stringify(publicPath)
51
61
  }
52
62
 
package/lib/helpers.js CHANGED
@@ -69,6 +69,8 @@ module.exports = function createHelpers (loaderContext) {
69
69
  if (part.useJSONJS) options.useJSONJS = true
70
70
  // eslint-disable-next-line no-fallthrough
71
71
  case 'styles':
72
+ options.lang = part.lang
73
+ // eslint-disable-next-line no-fallthrough
72
74
  case 'template':
73
75
  options.extract = true
74
76
  }
package/lib/index.js CHANGED
@@ -14,8 +14,7 @@ const EntryPlugin = require('webpack/lib/EntryPlugin')
14
14
  const JavascriptModulesPlugin = require('webpack/lib/javascript/JavascriptModulesPlugin')
15
15
  const FlagEntryExportAsUsedPlugin = require('webpack/lib/FlagEntryExportAsUsedPlugin')
16
16
  const FileSystemInfo = require('webpack/lib/FileSystemInfo')
17
- const ImportDependency = require('webpack/lib/dependencies/ImportDependency')
18
- const ImportDependencyTemplate = require('./dependencies/ImportDependencyTemplate')
17
+ const ImportDependency = require('./dependencies/ImportDependency')
19
18
  const AsyncDependenciesBlock = require('webpack/lib/AsyncDependenciesBlock')
20
19
  const ProvidePlugin = require('webpack/lib/ProvidePlugin')
21
20
  const normalize = require('./utils/normalize')
@@ -37,6 +36,7 @@ const FixDescriptionInfoPlugin = require('./resolver/FixDescriptionInfoPlugin')
37
36
  const AppEntryDependency = require('./dependencies/AppEntryDependency')
38
37
  const RecordPageConfigMapDependency = require('./dependencies/RecordPageConfigsMapDependency')
39
38
  const RecordResourceMapDependency = require('./dependencies/RecordResourceMapDependency')
39
+ const RecordModuleIdMapDependency = require('./dependencies/RecordModuleIdMapDependency')
40
40
  const RecordGlobalComponentsDependency = require('./dependencies/RecordGlobalComponentsDependency')
41
41
  const RecordIndependentDependency = require('./dependencies/RecordIndependentDependency')
42
42
  const DynamicEntryDependency = require('./dependencies/DynamicEntryDependency')
@@ -77,8 +77,10 @@ const VirtualModulesPlugin = require('webpack-virtual-modules')
77
77
  const RuntimeGlobals = require('webpack/lib/RuntimeGlobals')
78
78
  const LoadAsyncChunkModule = require('./react/LoadAsyncChunkModule')
79
79
  const ExternalModule = require('webpack/lib/ExternalModule')
80
- const { RetryRuntimeModule, RetryRuntimeGlobal } = require('./retry-runtime-module')
81
- require('./utils/check-core-version-match')
80
+ const { RetryRuntimeModule, RetryRuntimeGlobal } = require('./dependencies/RetryRuntimeModule')
81
+ const checkVersionCompatibility = require('./utils/check-core-version-match')
82
+
83
+ checkVersionCompatibility()
82
84
 
83
85
  const isProductionLikeMode = options => {
84
86
  return options.mode === 'production' || !options.mode
@@ -672,6 +674,9 @@ class MpxWebpackPlugin {
672
674
  compilation.dependencyFactories.set(RecordResourceMapDependency, new NullFactory())
673
675
  compilation.dependencyTemplates.set(RecordResourceMapDependency, new RecordResourceMapDependency.Template())
674
676
 
677
+ compilation.dependencyFactories.set(RecordModuleIdMapDependency, new NullFactory())
678
+ compilation.dependencyTemplates.set(RecordModuleIdMapDependency, new RecordModuleIdMapDependency.Template())
679
+
675
680
  compilation.dependencyFactories.set(RecordGlobalComponentsDependency, new NullFactory())
676
681
  compilation.dependencyTemplates.set(RecordGlobalComponentsDependency, new RecordGlobalComponentsDependency.Template())
677
682
 
@@ -696,7 +701,8 @@ class MpxWebpackPlugin {
696
701
  compilation.dependencyFactories.set(RequireExternalDependency, new NullFactory())
697
702
  compilation.dependencyTemplates.set(RequireExternalDependency, new RequireExternalDependency.Template())
698
703
 
699
- compilation.dependencyTemplates.set(ImportDependency, new ImportDependencyTemplate())
704
+ compilation.dependencyFactories.set(ImportDependency, normalModuleFactory)
705
+ compilation.dependencyTemplates.set(ImportDependency, new ImportDependency.Template())
700
706
  })
701
707
 
702
708
  compiler.hooks.thisCompilation.tap('MpxWebpackPlugin', (compilation, { normalModuleFactory }) => {
@@ -719,6 +725,8 @@ class MpxWebpackPlugin {
719
725
  componentsMap: {
720
726
  main: {}
721
727
  },
728
+ // 资源与moduleId关系记录
729
+ resourceModuleIdMap: {},
722
730
  // 静态资源(图片,字体,独立样式)等,依照所属包进行记录
723
731
  staticResourcesMap: {
724
732
  main: {}
@@ -1451,10 +1459,6 @@ class MpxWebpackPlugin {
1451
1459
  if (mpx.supportRequireAsync) {
1452
1460
  if (isWeb(mpx.mode) || isReact(mpx.mode)) {
1453
1461
  if (isReact(mpx.mode)) tarRoot = transSubpackage(mpx.transSubpackageRules, tarRoot)
1454
- request = addQuery(request, {
1455
- isRequireAsync: true,
1456
- retryRequireAsync: JSON.stringify(this.options.retryRequireAsync)
1457
- })
1458
1462
  const depBlock = new AsyncDependenciesBlock(
1459
1463
  {
1460
1464
  name: tarRoot + '/index'
@@ -1462,7 +1466,10 @@ class MpxWebpackPlugin {
1462
1466
  expr.loc,
1463
1467
  request
1464
1468
  )
1465
- const dep = new ImportDependency(request, expr.range)
1469
+ const dep = new ImportDependency(request, expr.range, undefined, {
1470
+ isRequireAsync: true,
1471
+ retryRequireAsync: this.options.retryRequireAsync
1472
+ })
1466
1473
  dep.loc = expr.loc
1467
1474
  depBlock.addDependency(dep)
1468
1475
  parser.state.current.addBlock(depBlock)
@@ -1683,11 +1690,12 @@ class MpxWebpackPlugin {
1683
1690
 
1684
1691
  if (this.options.generateBuildMap) {
1685
1692
  const pagesMap = compilation.__mpx__.pagesMap
1693
+ const resourceModuleIdMap = compilation.__mpx__.resourceModuleIdMap
1686
1694
  const componentsPackageMap = compilation.__mpx__.componentsMap
1687
1695
  const componentsMap = Object.keys(componentsPackageMap).map(item => componentsPackageMap[item]).reduce((pre, cur) => {
1688
1696
  return { ...pre, ...cur }
1689
1697
  }, {})
1690
- const outputMap = JSON.stringify({ ...pagesMap, ...componentsMap })
1698
+ const outputMap = JSON.stringify({ outputPathMap: { ...pagesMap, ...componentsMap }, moduleIdMap: resourceModuleIdMap })
1691
1699
  const filename = this.options.generateBuildMap.filename || 'outputMap.json'
1692
1700
  compilation.assets[filename] = new RawSource(outputMap)
1693
1701
  }
@@ -1899,24 +1907,41 @@ try {
1899
1907
  normalModuleFactory.hooks.afterResolve.tap('MpxWebpackPlugin', ({ createData }) => {
1900
1908
  const { queryObj } = parseRequest(createData.request)
1901
1909
  const loaders = createData.loaders
1910
+
1911
+ // 样式 loader 类型检测和条件编译 loader 插入的工具函数
1912
+ const STYLE_LOADER_TYPES = ['stylus-loader', 'sass-loader', 'less-loader', 'css-loader', wxssLoaderPath]
1913
+ const injectStyleStripLoader = (loaders) => {
1914
+ // 检查是否已经存在 stripLoader
1915
+ const hasStripLoader = loaders.some(loader => {
1916
+ const loaderPath = toPosix(loader.loader)
1917
+ return loaderPath.includes('style-compiler/strip-conditional-loader')
1918
+ })
1919
+ if (hasStripLoader) {
1920
+ return
1921
+ }
1922
+ const loaderTypes = new Map(STYLE_LOADER_TYPES.map(type => [`node_modules/${type}`, -1]))
1923
+ loaders.forEach((loader, index) => {
1924
+ const currentLoader = toPosix(loader.loader)
1925
+ for (const [key] of loaderTypes) {
1926
+ if (currentLoader.includes(key)) {
1927
+ loaderTypes.set(key, index)
1928
+ break
1929
+ }
1930
+ }
1931
+ })
1932
+ const targetIndex = STYLE_LOADER_TYPES
1933
+ .map(type => loaderTypes.get(`node_modules/${type}`))
1934
+ .find(index => index !== -1)
1935
+
1936
+ if (targetIndex !== undefined) {
1937
+ loaders.splice(targetIndex + 1, 0, { loader: styleStripConditionalPath })
1938
+ }
1939
+ }
1902
1940
  if (queryObj.mpx && queryObj.mpx !== MPX_PROCESSED_FLAG) {
1903
1941
  const type = queryObj.type
1904
1942
  const extract = queryObj.extract
1905
-
1906
1943
  if (type === 'styles') {
1907
- let insertBeforeIndex = -1
1908
- // 单次遍历收集所有索引
1909
- loaders.forEach((loader, index) => {
1910
- const currentLoader = toPosix(loader.loader)
1911
- if (currentLoader.includes('node_modules/stylus-loader') || currentLoader.includes('node_modules/sass-loader') || currentLoader.includes('node_modules/less-loader')) {
1912
- insertBeforeIndex = index
1913
- }
1914
- })
1915
-
1916
- if (insertBeforeIndex !== -1) {
1917
- loaders.splice(insertBeforeIndex, 0, { loader: styleStripConditionalPath })
1918
- }
1919
- loaders.push({ loader: styleStripConditionalPath })
1944
+ injectStyleStripLoader(loaders)
1920
1945
  }
1921
1946
 
1922
1947
  switch (type) {
@@ -1970,6 +1995,7 @@ try {
1970
1995
  }
1971
1996
  // mpxStyleOptions 为 mpx style 文件的标识,避免 Vue 文件插入 styleCompiler 后导致 vue scoped 样式隔离失效
1972
1997
  if (isWeb(mpx.mode) && queryObj.mpxStyleOptions) {
1998
+ injectStyleStripLoader(loaders)
1973
1999
  const firstLoader = loaders[0] ? toPosix(loaders[0].loader) : ''
1974
2000
  const isPitcherRequest = firstLoader.includes('node_modules/vue-loader/lib/loaders/pitcher')
1975
2001
  let cssLoaderIndex = -1
@@ -8,8 +8,10 @@ const loaderUtils = require('loader-utils')
8
8
  const resolve = require('../utils/resolve')
9
9
  const { matchCondition } = require('../utils/match-condition')
10
10
  const { isWeb, isReact } = require('../utils/env')
11
+ const getBuildInTagComponent = require('../utils/get-build-tag-component')
12
+ const { capitalToHyphen } = require('../utils/string')
11
13
 
12
- module.exports = function createJSONHelper ({ loaderContext, emitWarning, customGetDynamicEntry }) {
14
+ module.exports = function createJSONHelper ({ loaderContext, emitWarning, customGetDynamicEntry, emitError }) {
13
15
  const mpx = loaderContext.getMpx()
14
16
  const resolveMode = mpx.resolveMode
15
17
  const externals = mpx.externals
@@ -158,7 +160,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
158
160
  const { resourcePath } = parseRequest(resource)
159
161
  const relative = path.relative(context, resourcePath)
160
162
  if (/^\./.test(relative)) {
161
- return callback(new Error(`The js export path ${resourcePath} must be in the context ${context}!`))
163
+ return callback(new Error(`[Mpx json error]:The js export path ${resourcePath} must be in the context ${context}!`))
162
164
  }
163
165
  const outputPath = /^(.*?)(\.[^.]*)?$/.exec(relative)[1]
164
166
  const entry = getDynamicEntry(resource, 'export', outputPath, tarRoot, publicPath + tarRoot)
@@ -166,11 +168,79 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
166
168
  })
167
169
  }
168
170
 
171
+ const fillInComponentPlaceholder = ({ jsonObj, name: componentName, placeholder, placeholderEntry, resolveResourcePathMap }, callback) => {
172
+ let placeholderComponentName = placeholder.name
173
+ const componentPlaceholder = jsonObj.componentPlaceholder || {}
174
+ if (componentPlaceholder[componentName]) {
175
+ callback()
176
+ return
177
+ }
178
+ jsonObj.componentPlaceholder = componentPlaceholder
179
+ if (placeholderEntry) {
180
+ if (resolveResourcePathMap.has(placeholderComponentName) && resolveResourcePathMap.get(placeholderComponentName) !== placeholder.resourcePath) {
181
+ // 如果存在placeholder与已有usingComponents冲突, 重新生成一个组件名,在当前组件后增加一个数字
182
+ let i = 1
183
+ let newPlaceholder = placeholderComponentName + i
184
+ while (jsonObj.usingComponents[newPlaceholder]) {
185
+ newPlaceholder = placeholderComponentName + ++i
186
+ }
187
+ placeholderComponentName = newPlaceholder
188
+ }
189
+ jsonObj.usingComponents[placeholderComponentName] = placeholderEntry
190
+ resolveResourcePathMap.set(placeholderComponentName, placeholder.resourcePath)
191
+ }
192
+ componentPlaceholder[componentName] = placeholderComponentName
193
+ callback(null, {
194
+ name: placeholderComponentName,
195
+ entry: placeholderEntry
196
+ })
197
+ }
198
+
199
+ const getNormalizePlaceholder = (placeholder) => {
200
+ if (typeof placeholder === 'string') {
201
+ placeholder = getBuildInTagComponent(mode, placeholder) || { name: placeholder }
202
+ }
203
+ if (!placeholder.name) {
204
+ emitError('The asyncSubpackageRules configuration format of @mpxjs/webpack-plugin a is incorrect')
205
+ }
206
+ // ali 下与 rulesRunner 规则一致,组件名驼峰转连字符
207
+ if (mode === 'ali') {
208
+ placeholder.name = capitalToHyphen(placeholder.name)
209
+ }
210
+ return placeholder
211
+ }
212
+
213
+ const processPlaceholder = ({ jsonObj, context, name, tarRoot, placeholder, relativePath, resolveResourcePathMap }, callback) => {
214
+ if (tarRoot) {
215
+ if (placeholder) {
216
+ placeholder = getNormalizePlaceholder(placeholder)
217
+ if (placeholder.resource) {
218
+ processComponent(placeholder.resource, context, { relativePath }, (err, entry, { resourcePath }) => {
219
+ if (err) return callback(err)
220
+ placeholder.resourcePath = resourcePath
221
+ fillInComponentPlaceholder({ jsonObj, name, placeholder, placeholderEntry: entry, resolveResourcePathMap }, callback)
222
+ })
223
+ } else {
224
+ fillInComponentPlaceholder({ jsonObj, name, placeholder }, callback)
225
+ }
226
+ } else {
227
+ if (!jsonObj.componentPlaceholder || !jsonObj.componentPlaceholder[name]) {
228
+ const errMsg = `componentPlaceholder of "${name}" doesn't exist! \n\r`
229
+ emitError(errMsg)
230
+ }
231
+ callback()
232
+ }
233
+ } else {
234
+ callback()
235
+ }
236
+ }
237
+
169
238
  return {
170
239
  processComponent,
171
240
  processDynamicEntry,
172
241
  processPage,
173
242
  processJsExport,
243
+ processPlaceholder,
174
244
  isUrlRequest,
175
245
  urlToRequest
176
246
  }