@mpxjs/webpack-plugin 2.10.15-1 → 2.10.15-2

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.
package/lib/index.js CHANGED
@@ -199,6 +199,7 @@ class MpxWebpackPlugin {
199
199
  }, options.nativeConfig)
200
200
  options.webConfig = options.webConfig || {}
201
201
  options.rnConfig = options.rnConfig || {}
202
+ options.rnConfig.supportSubpackage = options.rnConfig.supportSubpackage !== undefined ? options.rnConfig.supportSubpackage : true
202
203
  options.partialCompileRules = options.partialCompileRules || null
203
204
  options.asyncSubpackageRules = options.asyncSubpackageRules || []
204
205
  options.optimizeRenderRules = options.optimizeRenderRules ? (Array.isArray(options.optimizeRenderRules) ? options.optimizeRenderRules : [options.optimizeRenderRules]) : []
@@ -1447,7 +1448,10 @@ class MpxWebpackPlugin {
1447
1448
  // 删除root query
1448
1449
  if (queryObj.root) request = addQuery(request, {}, false, ['root'])
1449
1450
  // wx、ali和web平台支持require.async,其余平台使用CommonJsAsyncDependency进行模拟抹平
1450
- if (mpx.supportRequireAsync) {
1451
+ const supportRequireAsync = isReact(mpx.mode)
1452
+ ? (mpx.supportRequireAsync && this.options.rnConfig.supportSubpackage)
1453
+ : mpx.supportRequireAsync
1454
+ if (supportRequireAsync) {
1451
1455
  if (isWeb(mpx.mode) || isReact(mpx.mode)) {
1452
1456
  if (isReact(mpx.mode)) tarRoot = transSubpackage(mpx.transSubpackageRules, tarRoot)
1453
1457
  request = addQuery(request, {
@@ -1726,6 +1730,23 @@ class MpxWebpackPlugin {
1726
1730
  source.add('// inject pageconfigmap for screen\n' +
1727
1731
  'var context = (function() { return this })() || Function("return this")();\n')
1728
1732
  source.add(`context.__mpxPageConfigsMap = ${JSON.stringify(mpx.pageConfigsMap)};\n`)
1733
+
1734
+ if (process.env.NODE_ENV !== 'production') {
1735
+ source.add(`
1736
+ ${globalObject}.__mpxClearAsyncChunkCache = ${globalObject}.__mpxClearAsyncChunkCache || function (ids) {
1737
+ ids = JSON.stringify(ids)
1738
+ var arr = ${globalObject}['${chunkLoadingGlobal}'] || []
1739
+ for (var i = arr.length - 1; i >= 0; i--) {
1740
+ if (JSON.stringify(arr[i][0]) === ids) {
1741
+ arr.splice(i, 1)
1742
+ }
1743
+ }
1744
+ };\n`)
1745
+ }
1746
+ } else {
1747
+ if (process.env.NODE_ENV !== 'production') {
1748
+ source.add(`${globalObject}.__mpxClearAsyncChunkCache && ${globalObject}.__mpxClearAsyncChunkCache(${JSON.stringify(chunk.ids)});\n`)
1749
+ }
1729
1750
  }
1730
1751
  source.add(originalSource)
1731
1752
  compilation.assets[chunkFile] = source
@@ -1825,6 +1846,7 @@ try {
1825
1846
 
1826
1847
  compilation.chunkGroups.forEach((chunkGroup) => {
1827
1848
  if (!chunkGroup.isInitial()) {
1849
+ isReact(mpx.mode) && chunkGroup.chunks.forEach((chunk) => processChunk(chunk, false, []))
1828
1850
  return
1829
1851
  }
1830
1852
 
@@ -547,6 +547,17 @@ module.exports = function getSpec ({ warn, error }) {
547
547
  // })
548
548
  // return cssMap
549
549
  // }
550
+ const formatBorder = ({ prop, value, selector }, { mode }) => {
551
+ value = value.trim()
552
+ if (value === 'none') {
553
+ return {
554
+ prop: 'borderWidth',
555
+ value: 0
556
+ }
557
+ } else {
558
+ return formatAbbreviation({ prop, value, selector }, { mode })
559
+ }
560
+ }
550
561
 
551
562
  return {
552
563
  supportedModes: ['ios', 'android', 'harmony'],
@@ -593,6 +604,12 @@ module.exports = function getSpec ({ warn, error }) {
593
604
  // android: formatBoxShadow,
594
605
  // harmony: formatBoxShadow
595
606
  // },
607
+ {
608
+ test: 'border',
609
+ ios: formatBorder,
610
+ android: formatBorder,
611
+ harmony: formatBorder
612
+ },
596
613
  // 通用的简写格式匹配
597
614
  {
598
615
  test: new RegExp('^(' + Object.keys(AbbreviationMap).join('|') + ')$'),
@@ -46,7 +46,8 @@ import { getComponent, getAsyncSuspense } from ${stringifyRequest(loaderContext,
46
46
  const componentsMap = buildComponentsMap({
47
47
  localComponentsMap,
48
48
  loaderContext,
49
- jsonConfig
49
+ jsonConfig,
50
+ rnConfig
50
51
  })
51
52
  output += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, ctorType, jsonConfig, componentsMap, pagesMap, firstPage, hasApp })
52
53
  output += getRequireScript({ ctorType, script, loaderContext })
@@ -58,7 +59,8 @@ import { getComponent, getAsyncSuspense } from ${stringifyRequest(loaderContext,
58
59
  localComponentsMap,
59
60
  builtInComponentsMap,
60
61
  loaderContext,
61
- jsonConfig
62
+ jsonConfig,
63
+ rnConfig
62
64
  })
63
65
 
64
66
  output += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, ctorType, jsonConfig, componentsMap, outputPath, genericsInfo, componentGenerics, hasApp })
@@ -59,7 +59,7 @@ function buildPagesMap ({ localPagesMap, loaderContext, jsonConfig, rnConfig })
59
59
  Object.keys(localPagesMap).forEach((pagePath) => {
60
60
  const pageCfg = localPagesMap[pagePath]
61
61
  const pageRequest = stringifyRequest(loaderContext, pageCfg.resource)
62
- if (pageCfg.async) {
62
+ if (pageCfg.async && rnConfig.supportSubpackage) {
63
63
  const moduleId = mpx.getModuleId(pageCfg.resource)
64
64
  const getFallback = rnConfig.asyncChunk && rnConfig.asyncChunk.fallback && getComponentGetter(getComponent(stringifyRequest(loaderContext, addQuery(rnConfig.asyncChunk.fallback, { isComponent: true })), 'PageFallback'))
65
65
  const getLoading = rnConfig.asyncChunk && rnConfig.asyncChunk.loading && getComponentGetter(getComponent(stringifyRequest(loaderContext, addQuery(rnConfig.asyncChunk.loading, { isComponent: true })), 'PageLoading'))
@@ -81,14 +81,14 @@ function buildPagesMap ({ localPagesMap, loaderContext, jsonConfig, rnConfig })
81
81
  }
82
82
  }
83
83
 
84
- function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderContext, jsonConfig }) {
84
+ function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderContext, jsonConfig, rnConfig }) {
85
85
  const componentsMap = {}
86
86
  const mpx = loaderContext.getMpx()
87
87
  if (localComponentsMap) {
88
88
  Object.keys(localComponentsMap).forEach((componentName) => {
89
89
  const componentCfg = localComponentsMap[componentName]
90
90
  const componentRequest = stringifyRequest(loaderContext, componentCfg.resource)
91
- if (componentCfg.async) {
91
+ if (componentCfg.async && rnConfig.supportSubpackage) {
92
92
  const moduleId = mpx.getModuleId(componentCfg.resource)
93
93
  const placeholder = jsonConfig.componentPlaceholder && jsonConfig.componentPlaceholder[componentName]
94
94
  let getFallback
@@ -100,8 +100,8 @@ const AsyncSuspense = ({ type, chunkName, moduleId, innerProps, getLoading, getF
100
100
  });
101
101
  });
102
102
  }
103
- if (type === 'page' && typeof mpxGlobal.__mpx.config?.rnConfig?.lazyLoadPageErrorHandler === 'function') {
104
- mpxGlobal.__mpx.config.rnConfig.lazyLoadPageErrorHandler({
103
+ if (type === 'page' && typeof mpxGlobal.__mpx.config?.rnConfig?.onLazyLoadPageError === 'function') {
104
+ mpxGlobal.__mpx.config.rnConfig.onLazyLoadPageError({
105
105
  subpackage: chunkName,
106
106
  errType: e.type
107
107
  });
@@ -157,8 +157,8 @@ const _PickerViewColumn = forwardRef((props, ref) => {
157
157
  }, [itemRawH, maxIndex, snapToOffsets, onMomentumScrollEnd, resetScrollPosition]);
158
158
  const onScroll = useCallback((e) => {
159
159
  // 全局注册的振动触感 hook
160
- const pickerVibrate = global.__mpx?.config?.rnConfig?.pickerVibrate;
161
- if (typeof pickerVibrate !== 'function') {
160
+ const onPickerVibrate = global.__mpx?.config?.rnConfig?.onPickerVibrate;
161
+ if (typeof onPickerVibrate !== 'function') {
162
162
  return;
163
163
  }
164
164
  const { y } = e.nativeEvent.contentOffset;
@@ -172,7 +172,7 @@ const _PickerViewColumn = forwardRef((props, ref) => {
172
172
  y: currentId * itemRawH
173
173
  };
174
174
  // vibrateShort({ type: 'selection' })
175
- pickerVibrate();
175
+ onPickerVibrate();
176
176
  }
177
177
  }
178
178
  }
@@ -292,20 +292,6 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
292
292
  snapScrollTop.current = y;
293
293
  }
294
294
  }
295
- function onScrollTouchStart(e) {
296
- const { bindtouchstart } = props;
297
- bindtouchstart && bindtouchstart(e);
298
- if (enhanced) {
299
- binddragstart &&
300
- binddragstart(getCustomEvent('dragstart', e, {
301
- detail: {
302
- scrollLeft: scrollOptions.current.scrollLeft,
303
- scrollTop: scrollOptions.current.scrollTop
304
- },
305
- layoutRef
306
- }, props));
307
- }
308
- }
309
295
  function onScrollTouchMove(e) {
310
296
  bindtouchmove && bindtouchmove(e);
311
297
  if (enhanced) {
@@ -319,19 +305,6 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
319
305
  }, props));
320
306
  }
321
307
  }
322
- function onScrollTouchEnd(e) {
323
- bindtouchend && bindtouchend(e);
324
- if (enhanced) {
325
- binddragend &&
326
- binddragend(getCustomEvent('dragend', e, {
327
- detail: {
328
- scrollLeft: scrollOptions.current.scrollLeft || 0,
329
- scrollTop: scrollOptions.current.scrollTop || 0
330
- },
331
- layoutRef
332
- }, props));
333
- }
334
- }
335
308
  function onScrollDrag(e) {
336
309
  const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset;
337
310
  updateScrollOptions(e, { scrollLeft, scrollTop });
@@ -347,6 +320,30 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
347
320
  hasCallScrollToLower.current = false;
348
321
  hasCallScrollToUpper.current = false;
349
322
  onScrollDrag(e);
323
+ if (enhanced) {
324
+ binddragstart &&
325
+ binddragstart(getCustomEvent('dragstart', e, {
326
+ detail: {
327
+ scrollLeft: scrollOptions.current.scrollLeft,
328
+ scrollTop: scrollOptions.current.scrollTop
329
+ },
330
+ layoutRef
331
+ }, props));
332
+ }
333
+ }
334
+ function onScrollDragEnd(e) {
335
+ onScrollDrag(e);
336
+ if (enhanced) {
337
+ // 安卓上如果触发了默认的下拉刷新,binddragend可能不触发,只会触发 binddragstart
338
+ binddragend &&
339
+ binddragend(getCustomEvent('dragend', e, {
340
+ detail: {
341
+ scrollLeft: scrollOptions.current.scrollLeft || 0,
342
+ scrollTop: scrollOptions.current.scrollTop || 0
343
+ },
344
+ layoutRef
345
+ }, props));
346
+ }
350
347
  }
351
348
  // 处理刷新
352
349
  function onRefresh() {
@@ -505,11 +502,9 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
505
502
  ref: scrollViewRef,
506
503
  onScroll: enableSticky ? scrollHandler : onScroll,
507
504
  onContentSizeChange: onContentSizeChange,
508
- bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
509
505
  bindtouchmove: ((enhanced && binddragging) || bindtouchmove) && onScrollTouchMove,
510
- bindtouchend: ((enhanced && binddragend) || bindtouchend) && onScrollTouchEnd,
511
506
  onScrollBeginDrag: onScrollDragStart,
512
- onScrollEndDrag: onScrollDrag,
507
+ onScrollEndDrag: onScrollDragEnd,
513
508
  onMomentumScrollEnd: onScrollEnd
514
509
  }, (simultaneousHandlers ? { simultaneousHandlers } : {}), (waitForHandlers ? { waitFor: waitForHandlers } : {}), layoutProps);
515
510
  if (enhanced) {
@@ -146,8 +146,8 @@ const AsyncSuspense: React.FC<AsyncSuspenseProps> = ({
146
146
  })
147
147
  })
148
148
  }
149
- if (type === 'page' && typeof mpxGlobal.__mpx.config?.rnConfig?.lazyLoadPageErrorHandler === 'function') {
150
- mpxGlobal.__mpx.config.rnConfig.lazyLoadPageErrorHandler({
149
+ if (type === 'page' && typeof mpxGlobal.__mpx.config?.rnConfig?.onLazyLoadPageError === 'function') {
150
+ mpxGlobal.__mpx.config.rnConfig.onLazyLoadPageError({
151
151
  subpackage: chunkName,
152
152
  errType: e.type
153
153
  })
@@ -223,8 +223,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
223
223
 
224
224
  const onScroll = useCallback((e: NativeSyntheticEvent<NativeScrollEvent>) => {
225
225
  // 全局注册的振动触感 hook
226
- const pickerVibrate = global.__mpx?.config?.rnConfig?.pickerVibrate
227
- if (typeof pickerVibrate !== 'function') {
226
+ const onPickerVibrate = global.__mpx?.config?.rnConfig?.onPickerVibrate
227
+ if (typeof onPickerVibrate !== 'function') {
228
228
  return
229
229
  }
230
230
  const { y } = e.nativeEvent.contentOffset
@@ -238,7 +238,7 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
238
238
  y: currentId * itemRawH
239
239
  }
240
240
  // vibrateShort({ type: 'selection' })
241
- pickerVibrate()
241
+ onPickerVibrate()
242
242
  }
243
243
  }
244
244
  }
@@ -455,22 +455,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
455
455
  }
456
456
  }
457
457
 
458
- function onScrollTouchStart (e: NativeSyntheticEvent<TouchEvent>) {
459
- const { bindtouchstart } = props
460
- bindtouchstart && bindtouchstart(e)
461
- if (enhanced) {
462
- binddragstart &&
463
- binddragstart(
464
- getCustomEvent('dragstart', e, {
465
- detail: {
466
- scrollLeft: scrollOptions.current.scrollLeft,
467
- scrollTop: scrollOptions.current.scrollTop
468
- },
469
- layoutRef
470
- }, props)
471
- )
472
- }
473
- }
474
458
  function onScrollTouchMove (e: NativeSyntheticEvent<TouchEvent>) {
475
459
  bindtouchmove && bindtouchmove(e)
476
460
  if (enhanced) {
@@ -487,22 +471,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
487
471
  }
488
472
  }
489
473
 
490
- function onScrollTouchEnd (e: NativeSyntheticEvent<TouchEvent>) {
491
- bindtouchend && bindtouchend(e)
492
- if (enhanced) {
493
- binddragend &&
494
- binddragend(
495
- getCustomEvent('dragend', e, {
496
- detail: {
497
- scrollLeft: scrollOptions.current.scrollLeft || 0,
498
- scrollTop: scrollOptions.current.scrollTop || 0
499
- },
500
- layoutRef
501
- }, props)
502
- )
503
- }
504
- }
505
-
506
474
  function onScrollDrag (e: NativeSyntheticEvent<NativeScrollEvent>) {
507
475
  const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
508
476
  updateScrollOptions(e, { scrollLeft, scrollTop })
@@ -523,6 +491,35 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
523
491
  hasCallScrollToLower.current = false
524
492
  hasCallScrollToUpper.current = false
525
493
  onScrollDrag(e)
494
+ if (enhanced) {
495
+ binddragstart &&
496
+ binddragstart(
497
+ getCustomEvent('dragstart', e, {
498
+ detail: {
499
+ scrollLeft: scrollOptions.current.scrollLeft,
500
+ scrollTop: scrollOptions.current.scrollTop
501
+ },
502
+ layoutRef
503
+ }, props)
504
+ )
505
+ }
506
+ }
507
+
508
+ function onScrollDragEnd (e: NativeSyntheticEvent<NativeScrollEvent>) {
509
+ onScrollDrag(e)
510
+ if (enhanced) {
511
+ // 安卓上如果触发了默认的下拉刷新,binddragend可能不触发,只会触发 binddragstart
512
+ binddragend &&
513
+ binddragend(
514
+ getCustomEvent('dragend', e, {
515
+ detail: {
516
+ scrollLeft: scrollOptions.current.scrollLeft || 0,
517
+ scrollTop: scrollOptions.current.scrollTop || 0
518
+ },
519
+ layoutRef
520
+ }, props)
521
+ )
522
+ }
526
523
  }
527
524
 
528
525
  // 处理刷新
@@ -695,11 +692,9 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
695
692
  ref: scrollViewRef,
696
693
  onScroll: enableSticky ? scrollHandler : onScroll,
697
694
  onContentSizeChange: onContentSizeChange,
698
- bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
699
695
  bindtouchmove: ((enhanced && binddragging) || bindtouchmove) && onScrollTouchMove,
700
- bindtouchend: ((enhanced && binddragend) || bindtouchend) && onScrollTouchEnd,
701
696
  onScrollBeginDrag: onScrollDragStart,
702
- onScrollEndDrag: onScrollDrag,
697
+ onScrollEndDrag: onScrollDragEnd,
703
698
  onMomentumScrollEnd: onScrollEnd
704
699
  },
705
700
  (simultaneousHandlers ? { simultaneousHandlers } : {}),
@@ -352,7 +352,7 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
352
352
  return extend({ app }, option)
353
353
  }
354
354
 
355
- export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue, VueRouter, tabBarMap, el }) {
355
+ export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue, VueRouter, tabBarMap, el, useSSR }) {
356
356
  if (!isBrowser) {
357
357
  return context => {
358
358
  const { app, router, pinia = {} } = createApp({
@@ -379,7 +379,7 @@ export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue
379
379
  }
380
380
  }
381
381
  } else {
382
- const { app, pinia } = createApp({
382
+ const { app, pinia, router } = createApp({
383
383
  App,
384
384
  componentsMap,
385
385
  Vue,
@@ -391,6 +391,14 @@ export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue
391
391
  if (window.__INITIAL_STATE__ && pinia) {
392
392
  pinia.state.value = window.__INITIAL_STATE__
393
393
  }
394
- app.$mount(el)
394
+ if (useSSR) {
395
+ // https://v3.router.vuejs.org/api/#router-onready
396
+ // ssr 场景如果使用了异步组件,需要在 onReady 回调中挂载,否则 hydrate 可能会报错
397
+ router.onReady(() => {
398
+ app.$mount(el)
399
+ })
400
+ } else {
401
+ app.$mount(el)
402
+ }
395
403
  }
396
404
  }
@@ -14,7 +14,7 @@ export function getAsyncSuspense (commonProps) {
14
14
  if (commonProps.type === 'component') {
15
15
  result = memo(forwardRef(function (props, ref) {
16
16
  return createElement(AsyncSuspense,
17
- extend(commonProps, {
17
+ extend({}, commonProps, {
18
18
  innerProps: Object.assign({}, props, { ref })
19
19
  })
20
20
  )
@@ -22,7 +22,7 @@ export function getAsyncSuspense (commonProps) {
22
22
  } else {
23
23
  result = memo(function (props) {
24
24
  return createElement(AsyncSuspense,
25
- extend(commonProps, {
25
+ extend({}, commonProps, {
26
26
  innerProps: props
27
27
  })
28
28
  )
@@ -71,7 +71,8 @@ export default processAppOption({
71
71
  componentsMap: ${shallowStringify(componentsMap)},
72
72
  Vue: Vue,
73
73
  VueRouter: VueRouter,
74
- el: ${JSON.stringify(webConfig.el || '#app')}
74
+ el: ${JSON.stringify(webConfig.el || '#app')},
75
+ useSSR: ${JSON.stringify(!!webConfig.useSSR)}
75
76
  })\n`
76
77
 
77
78
  callback(null, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.15-1",
3
+ "version": "2.10.15-2",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"