@mpxjs/webpack-plugin 2.10.17 → 2.10.18

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 (238) hide show
  1. package/lib/config.js +60 -0
  2. package/lib/file-loader.js +4 -1
  3. package/lib/global.d.ts +231 -0
  4. package/lib/index.js +58 -73
  5. package/lib/init.js +3 -0
  6. package/lib/json-compiler/index.js +13 -4
  7. package/lib/loader.js +4 -0
  8. package/lib/platform/json/wx/index.js +6 -0
  9. package/lib/platform/style/wx/index.js +102 -72
  10. package/lib/platform/template/wx/component-config/ad.js +5 -0
  11. package/lib/platform/template/wx/component-config/button.js +10 -3
  12. package/lib/platform/template/wx/component-config/camera.js +13 -3
  13. package/lib/platform/template/wx/component-config/canvas.js +8 -1
  14. package/lib/platform/template/wx/component-config/cover-image.js +7 -2
  15. package/lib/platform/template/wx/component-config/cover-view.js +3 -1
  16. package/lib/platform/template/wx/component-config/form.js +27 -2
  17. package/lib/platform/template/wx/component-config/image.js +5 -0
  18. package/lib/platform/template/wx/component-config/input.js +10 -0
  19. package/lib/platform/template/wx/component-config/label.js +10 -2
  20. package/lib/platform/template/wx/component-config/map.js +11 -0
  21. package/lib/platform/template/wx/component-config/movable-area.js +4 -1
  22. package/lib/platform/template/wx/component-config/movable-view.js +17 -2
  23. package/lib/platform/template/wx/component-config/navigator.js +26 -0
  24. package/lib/platform/template/wx/component-config/picker-view.js +12 -0
  25. package/lib/platform/template/wx/component-config/picker.js +3 -1
  26. package/lib/platform/template/wx/component-config/progress.js +11 -1
  27. package/lib/platform/template/wx/component-config/rich-text.js +5 -0
  28. package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
  29. package/lib/platform/template/wx/component-config/slider.js +8 -0
  30. package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
  31. package/lib/platform/template/wx/component-config/swiper.js +10 -0
  32. package/lib/platform/template/wx/component-config/text.js +5 -0
  33. package/lib/platform/template/wx/component-config/textarea.js +19 -2
  34. package/lib/platform/template/wx/component-config/unsupported.js +9 -0
  35. package/lib/platform/template/wx/component-config/video.js +10 -0
  36. package/lib/platform/template/wx/index.js +21 -1
  37. package/lib/react/LoadAsyncChunkModule.js +1 -1
  38. package/lib/react/processStyles.js +21 -9
  39. package/lib/react/script-helper.js +2 -2
  40. package/lib/react/style-helper.js +76 -13
  41. package/lib/resolver/AddModePlugin.js +17 -7
  42. package/lib/runtime/components/react/animationHooks/index.ts +75 -0
  43. package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +197 -0
  44. package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +301 -0
  45. package/lib/runtime/components/react/animationHooks/utils.ts +197 -0
  46. package/lib/runtime/components/react/context.ts +12 -3
  47. package/lib/runtime/components/react/dist/animationHooks/index.d.ts +15 -0
  48. package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
  49. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +3 -0
  50. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +181 -0
  51. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +3 -0
  52. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +279 -0
  53. package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +109 -0
  54. package/lib/runtime/components/react/dist/animationHooks/utils.js +151 -0
  55. package/lib/runtime/components/react/dist/context.d.ts +10 -3
  56. package/lib/runtime/components/react/dist/context.js +1 -2
  57. package/lib/runtime/components/react/dist/event.config.d.ts +0 -1
  58. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +0 -1
  59. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +0 -1
  60. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +3 -1
  61. package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -1
  62. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +0 -1
  63. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +0 -1
  64. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +0 -1
  65. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +0 -1
  66. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +0 -1
  67. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +0 -1
  68. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +0 -1
  69. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -1
  70. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +0 -1
  71. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -1
  72. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -1
  73. package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -1
  74. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -1
  75. package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
  76. package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
  77. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +0 -1
  78. package/lib/runtime/components/react/dist/mpx-input.d.ts +2 -1
  79. package/lib/runtime/components/react/dist/mpx-input.jsx +66 -50
  80. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +0 -1
  81. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +35 -6
  82. package/lib/runtime/components/react/dist/mpx-label.d.ts +0 -1
  83. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -1
  84. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +0 -1
  85. package/lib/runtime/components/react/dist/mpx-nav.d.ts +0 -1
  86. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +0 -1
  87. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +0 -1
  88. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +0 -1
  89. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +0 -1
  90. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +0 -1
  91. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +0 -1
  92. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +0 -1
  93. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +0 -1
  94. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +0 -1
  95. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +0 -1
  96. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +0 -1
  97. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -1
  98. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +0 -1
  99. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -1
  100. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -1
  101. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +0 -1
  102. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +0 -1
  103. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +0 -1
  104. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +0 -1
  105. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +0 -1
  106. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +0 -1
  107. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +0 -1
  108. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +0 -1
  109. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
  110. package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -1
  111. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -1
  112. package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -1
  113. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +0 -1
  114. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -1
  115. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +0 -1
  116. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +0 -1
  117. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +84 -78
  118. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +0 -1
  119. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +0 -1
  120. package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -1
  121. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -1
  122. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +20 -20
  123. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +0 -1
  124. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +0 -1
  125. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +10 -1
  126. package/lib/runtime/components/react/dist/mpx-swiper.jsx +95 -61
  127. package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -1
  128. package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -1
  129. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +0 -1
  130. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -0
  131. package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -1
  132. package/lib/runtime/components/react/dist/mpx-view.d.ts +3 -3
  133. package/lib/runtime/components/react/dist/mpx-view.jsx +22 -8
  134. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +0 -1
  135. package/lib/runtime/components/react/dist/parser.d.ts +0 -1
  136. package/lib/runtime/components/react/dist/useNodesRef.d.ts +0 -1
  137. package/lib/runtime/components/react/dist/utils.d.ts +10 -9
  138. package/lib/runtime/components/react/dist/utils.jsx +47 -24
  139. package/lib/runtime/components/react/mpx-async-suspense.tsx +3 -1
  140. package/lib/runtime/components/react/mpx-image.tsx +2 -2
  141. package/lib/runtime/components/react/mpx-input.tsx +77 -54
  142. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +35 -6
  143. package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
  144. package/lib/runtime/components/react/mpx-scroll-view.tsx +110 -114
  145. package/lib/runtime/components/react/mpx-sticky-header.tsx +24 -24
  146. package/lib/runtime/components/react/mpx-swiper.tsx +115 -60
  147. package/lib/runtime/components/react/mpx-textarea.tsx +1 -0
  148. package/lib/runtime/components/react/mpx-view.tsx +27 -12
  149. package/lib/runtime/components/react/tsconfig.json +26 -0
  150. package/lib/runtime/components/react/types/global.d.ts +1 -0
  151. package/lib/runtime/components/react/utils.tsx +51 -27
  152. package/lib/runtime/optionProcessor.js +5 -0
  153. package/lib/runtime/optionProcessorReact.js +7 -0
  154. package/lib/runtime/stringify.wxs +2 -2
  155. package/lib/script-setup-compiler/index.js +1 -2
  156. package/lib/style-compiler/strip-conditional.js +243 -0
  157. package/lib/template-compiler/compiler.js +2 -5
  158. package/lib/utils/string.js +25 -1
  159. package/lib/wxss/loader.js +4 -1
  160. package/lib/wxss/utils.js +7 -2
  161. package/package.json +7 -14
  162. package/lib/runtime/components/react/dist/context.d.ts.map +0 -1
  163. package/lib/runtime/components/react/dist/event.config.d.ts.map +0 -1
  164. package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +0 -1
  165. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +0 -1
  166. package/lib/runtime/components/react/dist/mpx-button.d.ts.map +0 -1
  167. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +0 -1
  168. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +0 -1
  169. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +0 -1
  170. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +0 -1
  171. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +0 -1
  172. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +0 -1
  173. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +0 -1
  174. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +0 -1
  175. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +0 -1
  176. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +0 -1
  177. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +0 -1
  178. package/lib/runtime/components/react/dist/mpx-form.d.ts.map +0 -1
  179. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +0 -1
  180. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +0 -1
  181. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +0 -1
  182. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +0 -1
  183. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +0 -1
  184. package/lib/runtime/components/react/dist/mpx-label.d.ts.map +0 -1
  185. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +0 -1
  186. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +0 -1
  187. package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +0 -1
  188. package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +0 -1
  189. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +0 -1
  190. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +0 -1
  191. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +0 -1
  192. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +0 -1
  193. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +0 -1
  194. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +0 -1
  195. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +0 -1
  196. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +0 -1
  197. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +0 -1
  198. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +0 -1
  199. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +0 -1
  200. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +0 -1
  201. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +0 -1
  202. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +0 -1
  203. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +0 -1
  204. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +0 -1
  205. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +0 -1
  206. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +0 -1
  207. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +0 -1
  208. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +0 -1
  209. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +0 -1
  210. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +0 -1
  211. package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +0 -1
  212. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +0 -1
  213. package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +0 -1
  214. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +0 -1
  215. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +0 -1
  216. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +0 -1
  217. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +0 -1
  218. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +0 -1
  219. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +0 -1
  220. package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +0 -1
  221. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +0 -1
  222. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +0 -1
  223. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +0 -1
  224. package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +0 -1
  225. package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +0 -1
  226. package/lib/runtime/components/react/dist/mpx-text.d.ts.map +0 -1
  227. package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +0 -1
  228. package/lib/runtime/components/react/dist/mpx-video.d.ts.map +0 -1
  229. package/lib/runtime/components/react/dist/mpx-view.d.ts.map +0 -1
  230. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +0 -1
  231. package/lib/runtime/components/react/dist/parser.d.ts.map +0 -1
  232. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +0 -33
  233. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +0 -1
  234. package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
  235. package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +0 -1
  236. package/lib/runtime/components/react/dist/utils.d.ts.map +0 -1
  237. package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
  238. package/lib/style-compiler/strip-conditional-loader.js +0 -289
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
@@ -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,
@@ -47,6 +49,7 @@ module.exports = function loader (content, prevOptions) {
47
49
  ? options.publicPath
48
50
  : `${options.publicPath}/`}${url}`
49
51
  }
52
+
50
53
  publicPath = JSON.stringify(publicPath)
51
54
  }
52
55
 
@@ -0,0 +1,231 @@
1
+ import * as webpack from 'webpack'
2
+
3
+ declare module 'webpack' {
4
+ interface Compilation {
5
+ __mpx__: MpxContext
6
+ }
7
+
8
+ interface Compiler {
9
+ __mpx__?: boolean
10
+ }
11
+ }
12
+
13
+ declare global {
14
+ type MpxLoaderContext<T> = webpack.LoaderContext<T> & {
15
+ getMpx(): MpxContext
16
+ }
17
+
18
+ interface MpxContext {
19
+ /**
20
+ * 用于使用 webpack-virtual-modules 功能,目前仅在输出 web 时支持使用
21
+ */
22
+ __vfs: any | null
23
+
24
+ /**
25
+ * app 信息,便于获取 appName
26
+ */
27
+ appInfo: {
28
+ resourcePath?: string
29
+ name?: string
30
+ [key: string]: any
31
+ }
32
+
33
+ /**
34
+ * pageConfig 信息
35
+ */
36
+ pageConfigsMap: Record<string, any>
37
+
38
+ /**
39
+ * pages 全局记录,无需区分主包/分包
40
+ */
41
+ pagesMap: Record<string, string>
42
+
43
+ /**
44
+ * 组件资源记录,按所属包进行记录(如 componentsMap.main)
45
+ */
46
+ componentsMap: Record<string, Record<string, string>>
47
+
48
+ /**
49
+ * 静态资源(图片、字体、独立样式)等,按所属包进行记录
50
+ */
51
+ staticResourcesMap: Record<string, Record<string, string>>
52
+
53
+ /**
54
+ * 用于记录命中 subpackageModulesRules 的 JS 模块分包归属,用于 JS 多分包冗余输出
55
+ */
56
+ subpackageModulesMap: Record<string, Record<string, string>>
57
+
58
+ /**
59
+ * 记录其他资源,如 pluginMain、pluginExport,无需区分主包/分包
60
+ */
61
+ otherResourcesMap: Record<string, any>
62
+
63
+ /**
64
+ * 记录独立分包
65
+ */
66
+ independentSubpackagesMap: Record<string, any>
67
+
68
+ subpackagesEntriesMap: Record<string, any>
69
+ postSubpackageEntriesMap: Record<string, any>
70
+ replacePathMap: Record<string, string>
71
+
72
+ /**
73
+ * 导出模块集合
74
+ */
75
+ exportModules: Set<any>
76
+
77
+ /**
78
+ * 记录动态添加入口的分包信息
79
+ */
80
+ dynamicEntryInfo: Record<string, any>
81
+
82
+ /**
83
+ * 记录 entryModule 与 entryNode 的对应关系,用于体积分析
84
+ */
85
+ entryNodeModulesMap: Map<any, any>
86
+
87
+ /**
88
+ * 记录与 asset 相关联的 modules,用于体积分析
89
+ */
90
+ assetsModulesMap: Map<string, Set<any>>
91
+
92
+ /**
93
+ * 记录与 asset 相关联的 AST,用于体积分析和 esCheck,避免重复 parse
94
+ */
95
+ assetsASTsMap: Map<string, any>
96
+
97
+ /**
98
+ * 记录 RequireExternalDependency 相关资源路径
99
+ */
100
+ externalRequestsMap: Map<string, any>
101
+
102
+ globalComponents: Record<string, any>
103
+ globalComponentsInfo: Record<string, any>
104
+
105
+ /**
106
+ * todo: es6 Map 读写性能高于 object,之后会逐步替换
107
+ */
108
+ wxsAssetsCache: Map<string, any>
109
+ addEntryPromiseMap: Map<string, Promise<any>>
110
+ currentPackageRoot: string
111
+ wxsContentMap: Record<string, string>
112
+
113
+ /**
114
+ * 是否强制使用页面构造函数
115
+ */
116
+ forceUsePageCtor: boolean
117
+
118
+ resolveMode: string
119
+ mode: string
120
+ srcMode: string
121
+ env: string
122
+ externalClasses: string[]
123
+ projectRoot: string
124
+ autoScopeRules: any
125
+ autoVirtualHostRules: any
126
+ customTextRules: any
127
+ transRpxRules: any
128
+ postcssInlineConfig: any
129
+ decodeHTMLText: boolean
130
+
131
+ /**
132
+ * native 文件专用配置
133
+ */
134
+ i18n: any | null
135
+ checkUsingComponentsRules: any
136
+ forceDisableBuiltInLoader: boolean
137
+
138
+ /**
139
+ * 默认的应用标题
140
+ */
141
+ appTitle: string
142
+
143
+ attributes: any[]
144
+ externals: any[]
145
+ useRelativePath: boolean
146
+ removedChunks: any[]
147
+ forceProxyEventRules: any
148
+
149
+ /**
150
+ * 若配置 disableRequireAsync=true,则全平台构建不支持异步分包
151
+ */
152
+ supportRequireAsync: boolean
153
+ partialCompileRules: any
154
+ asyncSubpackageRules: any[]
155
+ transSubpackageRules: any
156
+ optimizeRenderRules: any[]
157
+
158
+ addEntryModuleIssuer: (module: string, issuer: string) => void
159
+
160
+ /**
161
+ * 资源路径的哈希函数(用于生成输出唯一名)
162
+ */
163
+ pathHash: (resourcePath: string) => string
164
+
165
+ // 缓存与工具
166
+ loaderContentCache: Map<string, any>
167
+ extractedFilesCache: Map<string, string>
168
+
169
+ // 函数接口
170
+
171
+ /**
172
+ * 收集动态入口信息(分包、文件名、是否为页面、是否包含异步等)
173
+ */
174
+ collectDynamicEntryInfo: (info: { resource: string; packageName: string; filename: string; entryType: string; hasAsync: boolean }) => void
175
+
176
+ /**
177
+ * 添加入口(包装了 webpack 的 addEntry)
178
+ */
179
+ addEntry: (request: string, name: string, callback: (err?: Error, result?: any) => void) => any
180
+
181
+ getModuleId: (filePath: string, isApp?: boolean) => string
182
+ getEntryNode: (module: any, type?: string) => any
183
+
184
+ /**
185
+ * 根据资源路径和类型返回输出路径(支持自定义输出、冲突处理等)
186
+ */
187
+ getOutputPath: (resourcePath: string, type: string, opts?: { ext?: string; conflictPath?: string }) => string
188
+
189
+ /**
190
+ * 获取提取后的文件名(支持静态、插件、普通资源)
191
+ */
192
+ getExtractedFile: (resource: string, opts?: { error?: (err: Error) => void }) => string
193
+
194
+ recordResourceMap: (params: {
195
+ resourcePath: string
196
+ resourceType: string
197
+ outputPath?: string
198
+ packageRoot?: string
199
+ recordOnly?: boolean
200
+ warn?: (e: Error) => void
201
+ error?: (e: Error) => void
202
+ }) => { outputPath?: string; alreadyOutputted?: boolean }
203
+
204
+ getPackageInfo: (params: {
205
+ resource: string
206
+ resourceType: string
207
+ outputPath?: string
208
+ issuerResource?: string
209
+ warn?: (e: Error) => void
210
+ error?: (e: Error) => void
211
+ }) => { packageName: string; packageRoot: string; outputPath?: string; alreadyOutputted?: boolean }
212
+
213
+ // 运行时信息与注入相关
214
+ runtimeInfo: Record<string, any>
215
+ dynamicSlotDependencies: Record<string, any>
216
+ dynamicTemplateRuleRunner: any
217
+
218
+ /**
219
+ * 依据 package 注入到 mpx-custom-element-*.json 里面的组件路径
220
+ */
221
+ getPackageInjectedComponentsMap: (packageName?: string) => Record<string, string>
222
+
223
+ getPackageInjectedTemplateConfig: (packageName?: string) => any
224
+ injectDynamicSlotDependencies: (usingComponents: string, resourcePath: string) => string
225
+ changeHashNameForAstNode: (templateAst: string, componentsMap: any) => string
226
+ collectDynamicSlotDependencies: (packageName?: string) => void
227
+
228
+ // 其它任意扩展字段
229
+ [key: string]: any
230
+ }
231
+ }
package/lib/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ require('./init')
3
4
  const path = require('path')
4
5
  const { ConcatSource, RawSource } = require('webpack').sources
5
6
  const ResolveDependency = require('./dependencies/ResolveDependency')
@@ -58,7 +59,6 @@ const wxssLoaderPath = normalize.lib('wxss/index')
58
59
  const wxmlLoaderPath = normalize.lib('wxml/loader')
59
60
  const wxsLoaderPath = normalize.lib('wxs/loader')
60
61
  const styleCompilerPath = normalize.lib('style-compiler/index')
61
- const styleStripConditionalPath = normalize.lib('style-compiler/strip-conditional-loader')
62
62
  const templateCompilerPath = normalize.lib('template-compiler/index')
63
63
  const jsonCompilerPath = normalize.lib('json-compiler/index')
64
64
  const jsonThemeCompilerPath = normalize.lib('json-compiler/theme')
@@ -79,13 +79,17 @@ const LoadAsyncChunkModule = require('./react/LoadAsyncChunkModule')
79
79
  const ExternalModule = require('webpack/lib/ExternalModule')
80
80
  const { RetryRuntimeModule, RetryRuntimeGlobal } = require('./dependencies/RetryRuntimeModule')
81
81
  const checkVersionCompatibility = require('./utils/check-core-version-match')
82
-
82
+ const { startFSStripForCss, registerStripCompilation } = require('./style-compiler/strip-conditional')
83
83
  checkVersionCompatibility()
84
84
 
85
85
  const isProductionLikeMode = options => {
86
86
  return options.mode === 'production' || !options.mode
87
87
  }
88
88
 
89
+ /**
90
+ * @param {import('webpack').NormalModule} module
91
+ * @returns
92
+ */
89
93
  const isStaticModule = module => {
90
94
  if (!module.resource) return false
91
95
  const { queryObj } = parseRequest(module.resource)
@@ -322,7 +326,13 @@ class MpxWebpackPlugin {
322
326
  }
323
327
  }
324
328
 
329
+ /**
330
+ * @param {import('webpack').Compiler} compiler
331
+ */
325
332
  apply (compiler) {
333
+ // 注入 fs 代理
334
+ startFSStripForCss(this.options.defs)
335
+
326
336
  if (!compiler.__mpx__) {
327
337
  compiler.__mpx__ = true
328
338
  } else {
@@ -706,6 +716,7 @@ class MpxWebpackPlugin {
706
716
  })
707
717
 
708
718
  compiler.hooks.thisCompilation.tap('MpxWebpackPlugin', (compilation, { normalModuleFactory }) => {
719
+ registerStripCompilation(compilation)
709
720
  compilation.warnings.push(...warnings)
710
721
  compilation.errors.push(...errors)
711
722
  const moduleGraph = compilation.moduleGraph
@@ -1444,6 +1455,7 @@ class MpxWebpackPlugin {
1444
1455
  const context = parser.state.module.context
1445
1456
  const { queryObj, resourcePath } = parseRequest(request)
1446
1457
  let tarRoot = queryObj.root
1458
+
1447
1459
  if (!tarRoot && mpx.asyncSubpackageRules) {
1448
1460
  for (const item of mpx.asyncSubpackageRules) {
1449
1461
  if (matchCondition(resourcePath, item)) {
@@ -1452,49 +1464,49 @@ class MpxWebpackPlugin {
1452
1464
  }
1453
1465
  }
1454
1466
  }
1455
- if (tarRoot) {
1467
+ // TODO 后续考虑和 asyncSubpackageRules 配置合并
1468
+ if (isReact(mpx.mode)) tarRoot = transSubpackage(mpx.transSubpackageRules, tarRoot)
1469
+
1470
+ if (tarRoot && mpx.supportRequireAsync) {
1456
1471
  // 删除root query
1457
1472
  if (queryObj.root) request = addQuery(request, {}, false, ['root'])
1458
1473
  // wx、ali和web平台支持require.async,其余平台使用CommonJsAsyncDependency进行模拟抹平
1459
- if (mpx.supportRequireAsync) {
1460
- if (isWeb(mpx.mode) || isReact(mpx.mode)) {
1461
- if (isReact(mpx.mode)) tarRoot = transSubpackage(mpx.transSubpackageRules, tarRoot)
1462
- const depBlock = new AsyncDependenciesBlock(
1463
- {
1464
- name: tarRoot + '/index'
1465
- },
1466
- expr.loc,
1467
- request
1468
- )
1469
- const dep = new ImportDependency(request, expr.range, undefined, {
1470
- isRequireAsync: true,
1471
- retryRequireAsync: this.options.retryRequireAsync
1472
- })
1473
- dep.loc = expr.loc
1474
- depBlock.addDependency(dep)
1475
- parser.state.current.addBlock(depBlock)
1476
- } else {
1477
- const dep = new DynamicEntryDependency(range, request, 'export', '', tarRoot, '', context, {
1478
- isAsync: true,
1479
- isRequireAsync: true,
1480
- retryRequireAsync: this.options.retryRequireAsync,
1481
- requireAsyncRange: expr.range
1482
- })
1483
-
1484
- parser.state.current.addPresentationalDependency(dep)
1485
- // 包含require.async的模块不能被concatenate,避免DynamicEntryDependency中无法获取模块chunk以计算相对路径
1486
- parser.state.module.buildInfo.moduleConcatenationBailout = 'require async'
1487
- }
1474
+ if (isWeb(mpx.mode) || isReact(mpx.mode)) {
1475
+ const depBlock = new AsyncDependenciesBlock(
1476
+ {
1477
+ name: tarRoot + '/index'
1478
+ },
1479
+ expr.loc,
1480
+ request
1481
+ )
1482
+ const dep = new ImportDependency(request, expr.range, undefined, {
1483
+ isRequireAsync: true,
1484
+ retryRequireAsync: this.options.retryRequireAsync
1485
+ })
1486
+ dep.loc = expr.loc
1487
+ depBlock.addDependency(dep)
1488
+ parser.state.current.addBlock(depBlock)
1488
1489
  } else {
1489
- const range = expr.range
1490
- const dep = new CommonJsAsyncDependency(request, range)
1491
- parser.state.current.addDependency(dep)
1490
+ const dep = new DynamicEntryDependency(range, request, 'export', '', tarRoot, '', context, {
1491
+ isAsync: true,
1492
+ isRequireAsync: true,
1493
+ retryRequireAsync: this.options.retryRequireAsync,
1494
+ requireAsyncRange: expr.range
1495
+ })
1496
+
1497
+ parser.state.current.addPresentationalDependency(dep)
1498
+ // 包含require.async的模块不能被concatenate,避免DynamicEntryDependency中无法获取模块chunk以计算相对路径
1499
+ parser.state.module.buildInfo.moduleConcatenationBailout = 'require async'
1492
1500
  }
1493
- if (args) parser.walkExpressions(args)
1494
- return true
1495
1501
  } else {
1496
- compilation.errors.push(new Error(`The require async JS [${request}] need to declare subpackage name by root`))
1502
+ const dep = new CommonJsAsyncDependency(request, expr.range)
1503
+ parser.state.current.addDependency(dep)
1504
+ if (!tarRoot) {
1505
+ compilation.warnings.push(new Error(`The require async JS [${request}] need to declare subpackage name by root`))
1506
+ }
1497
1507
  }
1508
+ if (args) parser.walkExpressions(args)
1509
+ return true
1498
1510
  }
1499
1511
  }
1500
1512
 
@@ -1729,7 +1741,14 @@ class MpxWebpackPlugin {
1729
1741
 
1730
1742
  if (isReact(mpx.mode)) {
1731
1743
  // 添加 @refresh reset 注释用于在 React HMR 时刷新组件
1732
- source.add('/* @refresh reset */\n')
1744
+ if (process.env.NODE_ENV !== 'production') {
1745
+ source.add(`/* @refresh reset */
1746
+ if (module.hot) {
1747
+ module.hot.accept(() => {
1748
+ require("react-native").DevSettings.reload();
1749
+ });
1750
+ }\n`)
1751
+ }
1733
1752
  // 注入页面的配置,供screen前置设置导航情况
1734
1753
  if (isRuntime) {
1735
1754
  source.add('// inject pageconfigmap for screen\n' +
@@ -1907,42 +1926,9 @@ try {
1907
1926
  normalModuleFactory.hooks.afterResolve.tap('MpxWebpackPlugin', ({ createData }) => {
1908
1927
  const { queryObj } = parseRequest(createData.request)
1909
1928
  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
- }
1940
1929
  if (queryObj.mpx && queryObj.mpx !== MPX_PROCESSED_FLAG) {
1941
1930
  const type = queryObj.type
1942
1931
  const extract = queryObj.extract
1943
- if (type === 'styles') {
1944
- injectStyleStripLoader(loaders)
1945
- }
1946
1932
 
1947
1933
  switch (type) {
1948
1934
  case 'styles':
@@ -1995,7 +1981,6 @@ try {
1995
1981
  }
1996
1982
  // mpxStyleOptions 为 mpx style 文件的标识,避免 Vue 文件插入 styleCompiler 后导致 vue scoped 样式隔离失效
1997
1983
  if (isWeb(mpx.mode) && queryObj.mpxStyleOptions) {
1998
- injectStyleStripLoader(loaders)
1999
1984
  const firstLoader = loaders[0] ? toPosix(loaders[0].loader) : ''
2000
1985
  const isPitcherRequest = firstLoader.includes('node_modules/vue-loader/lib/loaders/pitcher')
2001
1986
  let cssLoaderIndex = -1
package/lib/init.js ADDED
@@ -0,0 +1,3 @@
1
+ const { rewriteFSForCss } = require('./style-compiler/strip-conditional')
2
+
3
+ rewriteFSForCss()
@@ -472,6 +472,11 @@ module.exports = function (content) {
472
472
  }
473
473
  }
474
474
 
475
+ const wrapTabBarAsset = (expr) => {
476
+ if (mode !== 'ks') return expr
477
+ return `(function(p){return typeof p === "string" && p.charAt(0) === "/" ? p.slice(1) : p})(${expr})`
478
+ }
479
+
475
480
  const processTabBar = (output) => {
476
481
  const tabBarCfg = config[mode].tabBar
477
482
  const itemKey = tabBarCfg.itemKey
@@ -480,11 +485,15 @@ module.exports = function (content) {
480
485
 
481
486
  if (json.tabBar && json.tabBar[itemKey]) {
482
487
  json.tabBar[itemKey].forEach((item, index) => {
483
- if (item[iconKey] && isUrlRequest(item[iconKey])) {
484
- output += `json.tabBar.${itemKey}[${index}].${iconKey} = require("${addQuery(urlToRequest(item[iconKey]), { useLocal: true })}");\n`
488
+ const iconPath = item[iconKey]
489
+ if (iconPath && isUrlRequest(iconPath)) {
490
+ const iconRequire = wrapTabBarAsset(`require("${addQuery(urlToRequest(iconPath), { useLocal: true })}")`)
491
+ output += `json.tabBar.${itemKey}[${index}].${iconKey} = ${iconRequire};\n`
485
492
  }
486
- if (item[activeIconKey] && isUrlRequest(item[activeIconKey])) {
487
- output += `json.tabBar.${itemKey}[${index}].${activeIconKey} = require("${addQuery(urlToRequest(item[activeIconKey]), { useLocal: true })}");\n`
493
+ const activeIconPath = item[activeIconKey]
494
+ if (activeIconPath && isUrlRequest(activeIconPath)) {
495
+ const activeIconRequire = wrapTabBarAsset(`require("${addQuery(urlToRequest(activeIconPath), { useLocal: true })}")`)
496
+ output += `json.tabBar.${itemKey}[${index}].${activeIconKey} = ${activeIconRequire};\n`
488
497
  }
489
498
  })
490
499
  }
package/lib/loader.js CHANGED
@@ -19,6 +19,10 @@ const processWeb = require('./web')
19
19
  const processReact = require('./react')
20
20
  const genMpxCustomElement = require('./runtime-render/gen-mpx-custom-element')
21
21
 
22
+ /**
23
+ * @this {MpxLoaderContext<any>}
24
+ * @param {string} content
25
+ */
22
26
  module.exports = function (content) {
23
27
  this.cacheable()
24
28
 
@@ -179,6 +179,7 @@ module.exports = function getSpec ({ warn, error }) {
179
179
  swan: addGlobalComponents,
180
180
  qq: addGlobalComponents,
181
181
  tt: addGlobalComponents,
182
+ ks: addGlobalComponents,
182
183
  jd: addGlobalComponents,
183
184
  web: fixComponentName,
184
185
  ios: fixComponentName,
@@ -284,6 +285,7 @@ module.exports = function getSpec ({ warn, error }) {
284
285
  'swan',
285
286
  'qq',
286
287
  'tt',
288
+ 'ks',
287
289
  'jd',
288
290
  'qa',
289
291
  'dd',
@@ -401,6 +403,7 @@ module.exports = function getSpec ({ warn, error }) {
401
403
  qq: fillGlobalComponents,
402
404
  swan: fillGlobalComponents,
403
405
  tt: fillGlobalComponents,
406
+ ks: fillGlobalComponents,
404
407
  jd: fillGlobalComponents
405
408
  },
406
409
  {
@@ -408,6 +411,7 @@ module.exports = function getSpec ({ warn, error }) {
408
411
  qq: deletePath({ noLog: true }),
409
412
  swan: deletePath({ noLog: true }),
410
413
  tt: deletePath({ noLog: true }),
414
+ ks: deletePath({ noLog: true }),
411
415
  jd: deletePath({ noLog: true })
412
416
  },
413
417
  {
@@ -446,6 +450,7 @@ module.exports = function getSpec ({ warn, error }) {
446
450
  qq: getTabBarRule(),
447
451
  swan: getTabBarRule(),
448
452
  tt: getTabBarRule(),
453
+ ks: getTabBarRule(),
449
454
  jd: getTabBarRule()
450
455
  },
451
456
  {
@@ -454,6 +459,7 @@ module.exports = function getSpec ({ warn, error }) {
454
459
  qq: getWindowRule(),
455
460
  swan: getWindowRule(),
456
461
  tt: getWindowRule(),
462
+ ks: getWindowRule(),
457
463
  jd: getWindowRule()
458
464
  }
459
465
  ]