@mpxjs/webpack-plugin 2.9.64 → 2.9.66

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 (80) hide show
  1. package/lib/config.js +38 -10
  2. package/lib/index.js +5 -1
  3. package/lib/platform/style/wx/index.js +66 -60
  4. package/lib/platform/template/wx/index.js +12 -8
  5. package/lib/react/processTemplate.js +4 -2
  6. package/lib/react/style-helper.js +2 -5
  7. package/lib/runtime/components/react/context.ts +8 -0
  8. package/lib/runtime/components/react/dist/context.js +1 -0
  9. package/lib/runtime/components/react/dist/mpx-button.jsx +2 -1
  10. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +2 -1
  11. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +3 -2
  12. package/lib/runtime/components/react/dist/mpx-form.jsx +2 -1
  13. package/lib/runtime/components/react/dist/mpx-icon.jsx +3 -2
  14. package/lib/runtime/components/react/dist/mpx-image/index.jsx +2 -1
  15. package/lib/runtime/components/react/dist/mpx-input.jsx +2 -1
  16. package/lib/runtime/components/react/dist/mpx-label.jsx +2 -1
  17. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +3 -2
  18. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +2 -1
  19. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +2 -1
  20. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +2 -1
  21. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +2 -1
  22. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +2 -1
  23. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +2 -1
  24. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +4 -2
  25. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +3 -2
  26. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +2 -1
  27. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +2 -1
  28. package/lib/runtime/components/react/dist/mpx-radio.jsx +3 -2
  29. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +13 -3
  30. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +78 -77
  31. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +2 -1
  32. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +3 -2
  33. package/lib/runtime/components/react/dist/mpx-switch.jsx +3 -2
  34. package/lib/runtime/components/react/dist/mpx-text.jsx +2 -1
  35. package/lib/runtime/components/react/dist/mpx-view.jsx +45 -15
  36. package/lib/runtime/components/react/dist/mpx-web-view.jsx +4 -3
  37. package/lib/runtime/components/react/dist/useAnimationHooks.js +215 -0
  38. package/lib/runtime/components/react/dist/useNodesRef.js +1 -5
  39. package/lib/runtime/components/react/dist/utils.jsx +50 -37
  40. package/lib/runtime/components/react/mpx-button.tsx +3 -1
  41. package/lib/runtime/components/react/mpx-checkbox-group.tsx +3 -1
  42. package/lib/runtime/components/react/mpx-checkbox.tsx +4 -1
  43. package/lib/runtime/components/react/mpx-form.tsx +2 -1
  44. package/lib/runtime/components/react/mpx-icon.tsx +3 -2
  45. package/lib/runtime/components/react/mpx-image/index.tsx +2 -1
  46. package/lib/runtime/components/react/mpx-input.tsx +2 -1
  47. package/lib/runtime/components/react/mpx-label.tsx +2 -1
  48. package/lib/runtime/components/react/mpx-movable-area.tsx +3 -2
  49. package/lib/runtime/components/react/mpx-movable-view.tsx +2 -1
  50. package/lib/runtime/components/react/mpx-picker/date.tsx +2 -1
  51. package/lib/runtime/components/react/mpx-picker/index.tsx +2 -1
  52. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +2 -1
  53. package/lib/runtime/components/react/mpx-picker/region.tsx +2 -1
  54. package/lib/runtime/components/react/mpx-picker/selector.tsx +2 -1
  55. package/lib/runtime/components/react/mpx-picker/time.tsx +4 -2
  56. package/lib/runtime/components/react/mpx-picker-view-column.tsx +3 -2
  57. package/lib/runtime/components/react/mpx-picker-view.tsx +2 -1
  58. package/lib/runtime/components/react/mpx-radio-group.tsx +2 -1
  59. package/lib/runtime/components/react/mpx-radio.tsx +3 -2
  60. package/lib/runtime/components/react/mpx-scroll-view.tsx +14 -2
  61. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +77 -75
  62. package/lib/runtime/components/react/mpx-swiper/index.tsx +4 -1
  63. package/lib/runtime/components/react/mpx-swiper-item.tsx +2 -1
  64. package/lib/runtime/components/react/mpx-switch.tsx +2 -1
  65. package/lib/runtime/components/react/mpx-text.tsx +2 -1
  66. package/lib/runtime/components/react/mpx-view.tsx +55 -23
  67. package/lib/runtime/components/react/mpx-web-view.tsx +4 -3
  68. package/lib/runtime/components/react/types/common.ts +8 -2
  69. package/lib/runtime/components/react/types/global.d.ts +11 -1
  70. package/lib/runtime/components/react/useAnimationHooks.ts +248 -0
  71. package/lib/runtime/components/react/useNodesRef.ts +1 -6
  72. package/lib/runtime/components/react/utils.tsx +71 -50
  73. package/lib/runtime/components/web/mpx-scroll-view.vue +25 -5
  74. package/lib/style-compiler/index.js +5 -4
  75. package/lib/template-compiler/compiler.js +127 -158
  76. package/lib/utils/const.js +2 -1
  77. package/lib/web/processStyles.js +6 -2
  78. package/lib/web/processTemplate.js +2 -3
  79. package/lib/wxml/loader.js +1 -1
  80. package/package.json +6 -4
@@ -1,7 +1,7 @@
1
1
  const JSON5 = require('json5')
2
2
  const he = require('he')
3
3
  const config = require('../config')
4
- const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../utils/const')
4
+ const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID, PARENT_MODULE_ID } = require('../utils/const')
5
5
  const normalize = require('../utils/normalize')
6
6
  const { normalizeCondition } = require('../utils/match-condition')
7
7
  const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
@@ -15,7 +15,7 @@ const { isNonPhrasingTag } = require('../utils/dom-tag-config')
15
15
  const setBaseWxml = require('../runtime-render/base-wxml')
16
16
  const { parseExp } = require('./parse-exps')
17
17
  const shallowStringify = require('../utils/shallow-stringify')
18
- const { isReact } = require('../utils/env')
18
+ const { isReact, isWeb } = require('../utils/env')
19
19
 
20
20
  const no = function () {
21
21
  return false
@@ -101,6 +101,7 @@ let moduleId
101
101
  let isNative
102
102
  let hasScoped
103
103
  let hasVirtualHost
104
+ let isCustomText
104
105
  let runtimeCompile
105
106
  let rulesRunner
106
107
  let currentEl
@@ -617,6 +618,7 @@ function parse (template, options) {
617
618
  isNative = options.isNative
618
619
  hasScoped = options.hasScoped
619
620
  hasVirtualHost = options.hasVirtualHost
621
+ isCustomText = options.isCustomText
620
622
  filePath = options.filePath
621
623
  i18n = options.i18n
622
624
  runtimeCompile = options.runtimeCompile
@@ -661,6 +663,14 @@ function parse (template, options) {
661
663
  const stack = []
662
664
  let root
663
665
  const meta = {}
666
+ if (isCustomText) {
667
+ meta.options = meta.options || {}
668
+ meta.options.isCustomText = true
669
+ }
670
+ if (hasVirtualHost) {
671
+ meta.options = meta.options || {}
672
+ meta.options.virtualHost = true
673
+ }
664
674
  let currentParent
665
675
  let multiRootError
666
676
  // 用于记录模板用到的组件,匹配引用组件,看是否有冗余
@@ -736,23 +746,22 @@ function parse (template, options) {
736
746
  const children = currentParent.children
737
747
  if (currentParent.tag !== 'text') {
738
748
  text = text.trim()
749
+ } else {
750
+ text = text.trim() ? text : ''
739
751
  }
740
-
741
752
  if ((!config[mode].wxs || currentParent.tag !== config[mode].wxs.tag) && options.decodeHTMLText) {
742
753
  text = he.decode(text)
743
754
  }
744
755
 
745
756
  if (text) {
746
- if (text !== ' ' || !children.length || children[children.length - 1].text !== ' ') {
747
- const el = {
748
- type: 3,
749
- // 支付宝小程序模板解析中未对Mustache进行特殊处理,无论是否decode都会解析失败,无解,只能支付宝侧进行修复
750
- text: decodeInMustache(text),
751
- parent: currentParent
752
- }
753
- children.push(el)
754
- runtimeCompile ? processTextDynamic(el) : processText(el)
757
+ const el = {
758
+ type: 3,
759
+ // 支付宝小程序模板解析中未对Mustache进行特殊处理,无论是否decode都会解析失败,无解,只能支付宝侧进行修复
760
+ text: decodeInMustache(text),
761
+ parent: currentParent
755
762
  }
763
+ children.push(el)
764
+ runtimeCompile ? processTextDynamic(el) : processText(el)
756
765
  }
757
766
  },
758
767
  comment: function comment (text) {
@@ -887,7 +896,7 @@ function postMoveBaseDirective (target, source, isDelete = true) {
887
896
  }
888
897
 
889
898
  function stringify (str) {
890
- if (mode === 'web') str = str.replace(/'/g, '"')
899
+ if (isWeb(mode)) str = str.replace(/'/g, '"')
891
900
  return JSON.stringify(str)
892
901
  }
893
902
 
@@ -2051,7 +2060,7 @@ function processWrapTextReact (el) {
2051
2060
  // }
2052
2061
 
2053
2062
  function injectWxs (meta, module, src) {
2054
- if (runtimeCompile || addWxsModule(meta, module, src) || isReact(mode)) {
2063
+ if (runtimeCompile || addWxsModule(meta, module, src) || isReact(mode) || isWeb(mode)) {
2055
2064
  return
2056
2065
  }
2057
2066
 
@@ -2139,96 +2148,76 @@ function isComponentNode (el, options) {
2139
2148
  return options.usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component'
2140
2149
  }
2141
2150
 
2142
- function processAliExternalClassesHack (el, options) {
2151
+ function processExternalClasses (el, options) {
2143
2152
  const isComponent = isComponentNode(el, options)
2144
- // 处理组件externalClass多层传递
2145
2153
  const classLikeAttrNames = isComponent ? ['class'].concat(options.externalClasses) : ['class']
2154
+
2146
2155
  classLikeAttrNames.forEach((classLikeAttrName) => {
2147
- let classLikeAttrValue = getAndRemoveAttr(el, classLikeAttrName).val
2156
+ const classLikeAttrValue = getAndRemoveAttr(el, classLikeAttrName).val
2148
2157
  if (classLikeAttrValue) {
2149
- options.externalClasses.forEach((className) => {
2150
- const reg = new RegExp('\\b' + className + '\\b', 'g')
2151
- const replacement = dash2hump(className)
2152
- classLikeAttrValue = classLikeAttrValue.replace(reg, `{{${replacement}||''}}`)
2153
- })
2154
- addAttrs(el, [{
2155
- name: classLikeAttrName,
2156
- value: classLikeAttrValue
2157
- }])
2158
+ if (mode === 'web') {
2159
+ processWebClass(classLikeAttrName, classLikeAttrValue, el, options)
2160
+ } else {
2161
+ processAliClass(classLikeAttrName, classLikeAttrValue, el, options)
2162
+ }
2158
2163
  }
2159
2164
  })
2160
2165
 
2161
2166
  if (hasScoped && isComponent) {
2162
- options.externalClasses.forEach((className) => {
2163
- const externalClass = getAndRemoveAttr(el, className).val
2164
- if (externalClass) {
2165
- addAttrs(el, [{
2166
- name: className,
2167
- value: `${externalClass} ${moduleId}`
2168
- }])
2169
- }
2170
- })
2171
- }
2172
- }
2173
-
2174
- // externalClasses只能模拟静态传递
2175
- function processWebExternalClassesHack (el, options) {
2176
- const staticClass = getAndRemoveAttr(el, 'class').val
2177
- if (staticClass) {
2178
- const classNames = staticClass.split(/\s+/)
2179
- const replacements = []
2180
- options.externalClasses.forEach((className) => {
2181
- const index = classNames.indexOf(className)
2182
- if (index > -1) {
2183
- replacements.push(`$attrs[${stringify(className)}]`)
2184
- classNames.splice(index, 1)
2185
- }
2167
+ const needAddModuleId = options.externalClasses.some((className) => {
2168
+ return el.attrsMap[className] || (mode === 'web' && el.attrsMap[':' + className])
2186
2169
  })
2187
2170
 
2188
- if (classNames.length) {
2171
+ if (needAddModuleId) {
2189
2172
  addAttrs(el, [{
2190
- name: 'class',
2191
- value: classNames.join(' ')
2173
+ name: PARENT_MODULE_ID,
2174
+ value: `${moduleId}`
2192
2175
  }])
2193
2176
  }
2194
-
2195
- if (replacements.length) {
2177
+ }
2178
+ function processWebClass (classLikeAttrName, classLikeAttrValue, el, options) {
2179
+ let classNames = classLikeAttrValue.split(/\s+/)
2180
+ let hasExternalClass = false
2181
+ classNames = classNames.map((className) => {
2182
+ if (options.externalClasses.includes(className)) {
2183
+ hasExternalClass = true
2184
+ return `($attrs[${stringify(className)}] || '')`
2185
+ }
2186
+ return stringify(className)
2187
+ })
2188
+ if (hasExternalClass) {
2189
+ classNames.push(`($attrs[${stringify(PARENT_MODULE_ID)}] || '')`)
2190
+ }
2191
+ if (classLikeAttrName === 'class') {
2196
2192
  const dynamicClass = getAndRemoveAttr(el, ':class').val
2197
- if (dynamicClass) replacements.push(dynamicClass)
2198
-
2193
+ if (dynamicClass) classNames.push(dynamicClass)
2199
2194
  addAttrs(el, [{
2200
2195
  name: ':class',
2201
- value: `[${replacements}]`
2196
+ value: `[${classNames}]`
2197
+ }])
2198
+ } else {
2199
+ addAttrs(el, [{
2200
+ name: ':' + classLikeAttrName,
2201
+ value: `[${classNames}].join(' ')`
2202
2202
  }])
2203
2203
  }
2204
2204
  }
2205
2205
 
2206
- // 处理externalClasses多层透传
2207
- const isComponent = isComponentNode(el, options)
2208
- if (isComponent) {
2209
- options.externalClasses.forEach((classLikeAttrName) => {
2210
- const classLikeAttrValue = getAndRemoveAttr(el, classLikeAttrName).val
2211
- if (classLikeAttrValue) {
2212
- const classNames = classLikeAttrValue.split(/\s+/)
2213
- const replacements = []
2214
- options.externalClasses.forEach((className) => {
2215
- const index = classNames.indexOf(className)
2216
- if (index > -1) {
2217
- replacements.push(`$attrs[${stringify(className)}]`)
2218
- classNames.splice(index, 1)
2219
- }
2220
- })
2221
-
2222
- if (classNames.length) {
2223
- replacements.unshift(stringify(classNames.join(' ')))
2224
- }
2225
-
2226
- addAttrs(el, [{
2227
- name: ':' + classLikeAttrName,
2228
- value: `[${replacements}].join(' ')`
2229
- }])
2230
- }
2206
+ function processAliClass (classLikeAttrName, classLikeAttrValue, el, options) {
2207
+ let hasExternalClass = false
2208
+ options.externalClasses.forEach((className) => {
2209
+ const reg = new RegExp('\\b' + className + '\\b', 'g')
2210
+ const replacementClassName = dash2hump(className)
2211
+ if (classLikeAttrValue.includes(className)) hasExternalClass = true
2212
+ classLikeAttrValue = classLikeAttrValue.replace(reg, `{{${replacementClassName} || ''}}`)
2231
2213
  })
2214
+ if (hasExternalClass) {
2215
+ classLikeAttrValue += ` {{${PARENT_MODULE_ID} || ''}}`
2216
+ }
2217
+ addAttrs(el, [{
2218
+ name: classLikeAttrName,
2219
+ value: classLikeAttrValue
2220
+ }])
2232
2221
  }
2233
2222
  }
2234
2223
 
@@ -2331,12 +2320,7 @@ function postProcessAliComponentRootView (el, options, meta) {
2331
2320
  function getVirtualHostRoot (options, meta) {
2332
2321
  if (srcMode === 'wx') {
2333
2322
  if (ctorType === 'component') {
2334
- if (mode === 'wx' && hasVirtualHost) {
2335
- // wx组件注入virtualHost配置
2336
- meta.options = meta.options || {}
2337
- meta.options.virtualHost = true
2338
- }
2339
- if (mode === 'web' && !hasVirtualHost) {
2323
+ if (isWeb(mode) && !hasVirtualHost) {
2340
2324
  // ali组件根节点实体化
2341
2325
  const rootView = createASTElement('view', [
2342
2326
  {
@@ -2352,7 +2336,8 @@ function getVirtualHostRoot (options, meta) {
2352
2336
  return rootView
2353
2337
  }
2354
2338
  if (isReact(mode) && !hasVirtualHost) {
2355
- const rootView = createASTElement('view', [
2339
+ const tagName = isCustomText ? 'text' : 'view'
2340
+ const rootView = createASTElement(tagName, [
2356
2341
  {
2357
2342
  name: 'class',
2358
2343
  value: `${MPX_ROOT_VIEW} host-${moduleId}`
@@ -2367,7 +2352,7 @@ function getVirtualHostRoot (options, meta) {
2367
2352
  return rootView
2368
2353
  }
2369
2354
  }
2370
- if (mode === 'web' && ctorType === 'page') {
2355
+ if (isWeb(mode) && ctorType === 'page') {
2371
2356
  return createASTElement('page')
2372
2357
  }
2373
2358
  }
@@ -2375,36 +2360,24 @@ function getVirtualHostRoot (options, meta) {
2375
2360
  }
2376
2361
 
2377
2362
  function processShow (el, options, root) {
2378
- // 开启 virtualhost 全部走 props 传递处理
2379
- // 未开启 virtualhost 直接绑定 display:none 到节点上
2380
2363
  let { val: show, has } = getAndRemoveAttr(el, config[mode].directive.show)
2381
2364
  if (mode === 'swan') show = wrapMustache(show)
2382
2365
  if (has && show === undefined) {
2383
2366
  error$1(`Attrs ${config[mode].directive.show} should have a value `)
2367
+ return
2384
2368
  }
2385
- if (hasVirtualHost) {
2386
- if (ctorType === 'component' && el.parent === root && isRealNode(el)) {
2387
- if (show !== undefined) {
2388
- show = `{{${parseMustacheWithContext(show).result}&&mpxShow}}`
2389
- } else {
2390
- show = '{{mpxShow}}'
2391
- }
2392
- }
2393
- if (isComponentNode(el, options) && show !== undefined) {
2394
- if (show === '') {
2395
- show = '{{false}}'
2396
- }
2397
- addAttrs(el, [{
2398
- name: 'mpxShow',
2399
- value: show
2400
- }])
2401
- } else {
2402
- if (runtimeCompile) {
2403
- processShowStyleDynamic(el, show)
2404
- } else {
2405
- processShowStyle(el, show)
2406
- }
2369
+ if (ctorType === 'component' && el.parent === root && isRealNode(el)) {
2370
+ show = has ? `{{${parseMustacheWithContext(show).result}&&mpxShow}}` : '{{mpxShow}}'
2371
+ }
2372
+ if (show === undefined) return
2373
+ if (isComponentNode(el, options)) {
2374
+ if (show === '') {
2375
+ show = '{{false}}'
2407
2376
  }
2377
+ addAttrs(el, [{
2378
+ name: 'mpxShow',
2379
+ value: show
2380
+ }])
2408
2381
  } else {
2409
2382
  if (runtimeCompile) {
2410
2383
  processShowStyleDynamic(el, show)
@@ -2415,15 +2388,13 @@ function processShow (el, options, root) {
2415
2388
  }
2416
2389
 
2417
2390
  function processShowStyle (el, show) {
2418
- if (show !== undefined) {
2419
- const showExp = parseMustacheWithContext(show).result
2420
- let oldStyle = getAndRemoveAttr(el, 'style').val
2421
- oldStyle = oldStyle ? oldStyle + ';' : ''
2422
- addAttrs(el, [{
2423
- name: 'style',
2424
- value: `${oldStyle}{{${showExp}?'':'display:none;'}}`
2425
- }])
2426
- }
2391
+ const showExp = parseMustacheWithContext(show).result
2392
+ let oldStyle = getAndRemoveAttr(el, 'style').val
2393
+ oldStyle = oldStyle ? oldStyle + ';' : ''
2394
+ addAttrs(el, [{
2395
+ name: 'style',
2396
+ value: `${oldStyle}{{${showExp}?'':'display:none;'}}`
2397
+ }])
2427
2398
  }
2428
2399
 
2429
2400
  function processTemplate (el) {
@@ -2560,7 +2531,7 @@ function processDuplicateAttrsList (el) {
2560
2531
  }
2561
2532
 
2562
2533
  // 处理wxs注入逻辑
2563
- function processInjectWxs (el, meta, options) {
2534
+ function processInjectWxs (el, meta) {
2564
2535
  if (el.injectWxsProps && el.injectWxsProps.length) {
2565
2536
  el.injectWxsProps.forEach((injectWxsProp) => {
2566
2537
  const { injectWxsPath, injectWxsModuleName } = injectWxsProp
@@ -2610,12 +2581,14 @@ function processElement (el, root, options, meta) {
2610
2581
 
2611
2582
  const transAli = mode === 'ali' && srcMode === 'wx'
2612
2583
 
2613
- if (mode === 'web') {
2584
+ if (isWeb(mode)) {
2614
2585
  // 收集内建组件
2615
2586
  processBuiltInComponents(el, meta)
2616
2587
  // 预处理代码维度条件编译
2617
2588
  processIfWeb(el)
2618
- processWebExternalClassesHack(el, options)
2589
+ processScoped(el)
2590
+ // processWebExternalClassesHack(el, options)
2591
+ processExternalClasses(el, options)
2619
2592
  processComponentGenericsWeb(el, options, meta)
2620
2593
  return
2621
2594
  }
@@ -2635,7 +2608,7 @@ function processElement (el, root, options, meta) {
2635
2608
  return
2636
2609
  }
2637
2610
 
2638
- const pass = isNative || processTemplate(el) || processingTemplate
2611
+ const isTemplate = processTemplate(el) || processingTemplate
2639
2612
 
2640
2613
  // 仅ali平台需要scoped模拟样式隔离
2641
2614
  if (mode === 'ali') {
@@ -2643,24 +2616,25 @@ function processElement (el, root, options, meta) {
2643
2616
  }
2644
2617
 
2645
2618
  if (transAli) {
2646
- processAliExternalClassesHack(el, options)
2619
+ // processAliExternalClassesHack(el, options)
2620
+ processExternalClasses(el, options)
2647
2621
  }
2648
2622
 
2649
2623
  processIf(el)
2650
2624
  processFor(el)
2651
2625
 
2652
- if (!pass) {
2653
- processRef(el, options, meta)
2626
+ if (!isNative) {
2627
+ if (!isTemplate) processRef(el, options, meta)
2654
2628
  if (runtimeCompile) {
2655
- processClassDynamic(el, meta)
2656
- processStyleDynamic(el, meta)
2629
+ processClassDynamic(el)
2630
+ processStyleDynamic(el)
2657
2631
  } else {
2658
2632
  processClass(el, meta)
2659
2633
  processStyle(el, meta)
2660
2634
  }
2661
2635
  processShow(el, options, root)
2662
2636
  processEvent(el, options)
2663
- processComponentIs(el, options)
2637
+ if (!isTemplate) processComponentIs(el, options)
2664
2638
  }
2665
2639
 
2666
2640
  processAttrs(el, options)
@@ -2668,23 +2642,21 @@ function processElement (el, root, options, meta) {
2668
2642
 
2669
2643
  function closeElement (el, meta, options) {
2670
2644
  postProcessAtMode(el)
2671
- collectDynamicInfo(el, options, meta)
2645
+ postProcessWxs(el, meta)
2672
2646
 
2673
- if (mode === 'web') {
2674
- postProcessWxs(el, meta)
2647
+ if (isWeb(mode)) {
2675
2648
  // 处理代码维度条件编译移除死分支
2676
2649
  postProcessIf(el)
2677
2650
  return
2678
2651
  }
2679
2652
  if (isReact(mode)) {
2680
- postProcessWxs(el, meta)
2681
2653
  postProcessForReact(el)
2682
2654
  postProcessIfReact(el)
2683
2655
  return
2684
2656
  }
2685
- const pass = isNative || postProcessTemplate(el) || processingTemplate
2686
- postProcessWxs(el, meta)
2687
- if (!pass) {
2657
+
2658
+ const isTemplate = postProcessTemplate(el) || processingTemplate
2659
+ if (!isNative && !isTemplate) {
2688
2660
  if (isComponentNode(el, options) && !hasVirtualHost && mode === 'ali') {
2689
2661
  postProcessAliComponentRootView(el, options, meta)
2690
2662
  }
@@ -2694,6 +2666,7 @@ function closeElement (el, meta, options) {
2694
2666
  if (runtimeCompile) {
2695
2667
  postProcessForDynamic(el, config[mode])
2696
2668
  postProcessIfDynamic(el, config[mode])
2669
+ collectDynamicInfo(el, options, meta)
2697
2670
  postProcessAttrsDynamic(el, config[mode])
2698
2671
  } else {
2699
2672
  postProcessFor(el)
@@ -2796,9 +2769,7 @@ function serialize (root) {
2796
2769
  result += node.text
2797
2770
  }
2798
2771
  }
2799
- if (node.tag === 'wxs' && mode === 'web') {
2800
- return result
2801
- }
2772
+
2802
2773
  if (node.type === 1) {
2803
2774
  if (node.tag !== 'temp-node') {
2804
2775
  result += '<' + node.tag
@@ -2968,11 +2939,11 @@ function processIfConditionsDynamic (el) {
2968
2939
  block: el,
2969
2940
  __exp: el.elseif ? parseExp(el.elseif.exp) : ''
2970
2941
  })
2971
- removeNode(el)
2942
+ removeNode(el, true)
2972
2943
  }
2973
2944
  }
2974
2945
 
2975
- function processClassDynamic (el, meta) {
2946
+ function processClassDynamic (el) {
2976
2947
  const type = 'class'
2977
2948
  const targetType = type
2978
2949
  const dynamicClass = getAndRemoveAttr(el, config[mode].directive.dynamicClass).val
@@ -2995,7 +2966,7 @@ function processClassDynamic (el, meta) {
2995
2966
  }
2996
2967
  }
2997
2968
 
2998
- function processStyleDynamic (el, meta) {
2969
+ function processStyleDynamic (el) {
2999
2970
  const type = 'style'
3000
2971
  const targetType = type
3001
2972
  const dynamicStyle = getAndRemoveAttr(el, config[mode].directive.dynamicStyle).val
@@ -3084,17 +3055,15 @@ function postProcessAttrsDynamic (vnode, config) {
3084
3055
  }
3085
3056
 
3086
3057
  function processShowStyleDynamic (el, show) {
3087
- if (show !== undefined) {
3088
- const showExp = parseMustacheWithContext(show).result
3089
- const oldStyle = getAndRemoveAttr(el, 'style').val
3090
- const displayExp = `${showExp}? '' : "display:none;"`
3091
- const isArray = oldStyle?.endsWith(']}}')
3092
- const value = isArray ? oldStyle?.replace(']}}', `,${displayExp}]}}`) : `${oldStyle ? `${oldStyle};` : ''}{{${displayExp}}}`
3093
- addAttrs(el, [{
3094
- name: 'style',
3095
- value: value
3096
- }])
3097
- }
3058
+ const showExp = parseMustacheWithContext(show).result
3059
+ const oldStyle = getAndRemoveAttr(el, 'style').val
3060
+ const displayExp = `${showExp}? '' : "display:none;"`
3061
+ const isArray = oldStyle?.endsWith(']}}')
3062
+ const value = isArray ? oldStyle?.replace(']}}', `,${displayExp}]}}`) : `${oldStyle ? `${oldStyle};` : ''}{{${displayExp}}}`
3063
+ addAttrs(el, [{
3064
+ name: 'style',
3065
+ value: value
3066
+ }])
3098
3067
  }
3099
3068
 
3100
3069
  module.exports = {
@@ -5,5 +5,6 @@ module.exports = {
5
5
  RESOLVE_IGNORED_ERR: new Error('Resolve ignored!'),
6
6
  JSON_JS_EXT: '.json.js',
7
7
  MPX_ROOT_VIEW: 'mpx-root-view', // 根节点类名
8
- MPX_APP_MODULE_ID: 'mpx-app-scope' // app文件moduleId
8
+ MPX_APP_MODULE_ID: 'mpx-app-scope', // app文件moduleId
9
+ PARENT_MODULE_ID: '__pid'
9
10
  }
@@ -8,8 +8,12 @@ module.exports = function (styles, options, callback) {
8
8
  attrs (style) {
9
9
  const attrs = Object.assign({}, style.attrs)
10
10
  if (options.autoScope) attrs.scoped = true
11
- // query中包含module字符串会被新版vue-cli中的默认rules当做css-module处理
12
- attrs.mid = options.moduleId
11
+ attrs.mpxStyleOptions = JSON.stringify({
12
+ scoped: attrs.scoped,
13
+ // query中包含module字符串会被新版vue-cli中的默认rules当做css-module处理
14
+ mid: options.moduleId
15
+ })
16
+ delete attrs.scoped
13
17
  return attrs
14
18
  }
15
19
  })
@@ -6,7 +6,7 @@ const { matchCondition } = require('../utils/match-condition')
6
6
 
7
7
  module.exports = function (template, {
8
8
  loaderContext,
9
- // hasScoped,
9
+ hasScoped,
10
10
  hasComment,
11
11
  isNative,
12
12
  srcMode,
@@ -83,8 +83,7 @@ module.exports = function (template, {
83
83
  defs,
84
84
  decodeHTMLText,
85
85
  externalClasses,
86
- // todo 后续输出web也采用mpx的scoped处理
87
- hasScoped: false,
86
+ hasScoped,
88
87
  moduleId,
89
88
  filePath: resourcePath,
90
89
  i18n: null,
@@ -22,7 +22,7 @@ module.exports = function (content) {
22
22
  const { queryObj } = parseRequest(this.resource)
23
23
  const hasScoped = false
24
24
  const hasComment = false
25
- const isNative = true
25
+ const isNative = false
26
26
 
27
27
  const mode = mpx.mode
28
28
  const localSrcMode = queryObj.mode
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.64",
3
+ "version": "2.9.66",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -28,7 +28,7 @@
28
28
  "@better-scroll/wheel": "^2.5.1",
29
29
  "@better-scroll/zoom": "^2.5.1",
30
30
  "@mpxjs/template-engine": "^2.8.7",
31
- "@mpxjs/utils": "^2.9.64",
31
+ "@mpxjs/utils": "^2.9.65",
32
32
  "acorn": "^8.11.3",
33
33
  "acorn-walk": "^7.2.0",
34
34
  "async": "^2.6.0",
@@ -82,18 +82,20 @@
82
82
  },
83
83
  "devDependencies": {
84
84
  "@ant-design/react-native": "^5.2.2",
85
- "@mpxjs/api-proxy": "^2.9.64",
85
+ "@mpxjs/api-proxy": "^2.9.66",
86
86
  "@types/babel-traverse": "^6.25.4",
87
87
  "@types/babel-types": "^7.0.4",
88
88
  "@types/react": "^18.2.79",
89
89
  "react-native": "^0.74.5",
90
90
  "react-native-gesture-handler": "^2.18.1",
91
91
  "react-native-linear-gradient": "^2.8.3",
92
+ "react-native-reanimated": "^3.15.2",
93
+ "react-native-safe-area-context": "^4.12.0",
92
94
  "react-native-webview": "^13.12.2",
93
95
  "rimraf": "^6.0.1"
94
96
  },
95
97
  "engines": {
96
98
  "node": ">=14.14.0"
97
99
  },
98
- "gitHead": "803334dc0e600f219d514c27461aa7663b7a6653"
100
+ "gitHead": "ff9eb06a3be28538870823cebf813ed56f39bbd7"
99
101
  }