@mpxjs/webpack-plugin 2.8.50 → 2.8.51

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
@@ -173,6 +173,12 @@ class MpxWebpackPlugin {
173
173
  options.retryRequireAsync = options.retryRequireAsync || false
174
174
  options.enableAliRequireAsync = options.enableAliRequireAsync || false
175
175
  options.optimizeSize = options.optimizeSize || false
176
+ let proxyComponentEventsRules = []
177
+ const proxyComponentEventsRulesRaw = options.proxyComponentEventsRules
178
+ if (proxyComponentEventsRulesRaw) {
179
+ proxyComponentEventsRules = Array.isArray(proxyComponentEventsRulesRaw) ? proxyComponentEventsRulesRaw : [proxyComponentEventsRulesRaw]
180
+ }
181
+ options.proxyComponentEventsRules = proxyComponentEventsRules
176
182
  this.options = options
177
183
  // Hack for buildDependencies
178
184
  const rawResolveBuildDependencies = FileSystemInfo.prototype.resolveBuildDependencies
@@ -640,6 +646,7 @@ class MpxWebpackPlugin {
640
646
  enableRequireAsync: this.options.mode === 'wx' || (this.options.mode === 'ali' && this.options.enableAliRequireAsync),
641
647
  partialCompile: this.options.partialCompile,
642
648
  asyncSubpackageRules: this.options.asyncSubpackageRules,
649
+ proxyComponentEventsRules: this.options.proxyComponentEventsRules,
643
650
  pathHash: (resourcePath) => {
644
651
  if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
645
652
  return hash(path.relative(this.options.projectRoot, resourcePath))
package/lib/loader.js CHANGED
@@ -280,7 +280,7 @@ module.exports = function (content) {
280
280
  let ctor = 'App'
281
281
  if (ctorType === 'page') {
282
282
  // swan也默认使用Page构造器
283
- if (mpx.forceUsePageCtor || mode === 'ali' || mode === 'swan') {
283
+ if (mpx.forceUsePageCtor || mode === 'ali') {
284
284
  ctor = 'Page'
285
285
  } else {
286
286
  ctor = 'Component'
@@ -214,7 +214,7 @@ module.exports = function (content) {
214
214
  let ctorType = 'app'
215
215
  if (pagesMap[resourcePath]) {
216
216
  ctorType = 'page'
217
- if (mpx.forceUsePageCtor || mode === 'ali' || mode === 'swan') {
217
+ if (mpx.forceUsePageCtor || mode === 'ali') {
218
218
  ctor = 'Page'
219
219
  } else {
220
220
  ctor = 'Component'
@@ -345,7 +345,11 @@
345
345
  class: 'circle circle-c'
346
346
  }),
347
347
  ]
348
- ) : null
348
+ ) : this.$slots.refresher
349
+ ? createElement('div', {
350
+ class: 'mpx-pull-down-slot',
351
+ }, this.$slots.refresher)
352
+ : null
349
353
 
350
354
  const pullDownWrapper = this.refresherEnabled ? createElement('div', {
351
355
  class: 'mpx-pull-down-wrapper',
@@ -379,7 +383,11 @@
379
383
  bottom: 20px
380
384
  left: 50%
381
385
  transform: translateX(-50%)
382
-
386
+ .mpx-pull-down-slot
387
+ position: absolute
388
+ width: 100%
389
+ height: auto
390
+ bottom: 0
383
391
  .mpx-pull-down-content-black
384
392
  .circle
385
393
  display: inline-block;
@@ -47,6 +47,10 @@ module.exports = function (css, map) {
47
47
  plugins.push(transSpecial({ id }))
48
48
  }
49
49
 
50
+ if (mode === 'web') {
51
+ plugins.push(transSpecial({ id }))
52
+ }
53
+
50
54
  plugins.push(pluginCondStrip({
51
55
  defs
52
56
  }))
@@ -3,7 +3,6 @@ const he = require('he')
3
3
  const config = require('../config')
4
4
  const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../utils/const')
5
5
  const normalize = require('../utils/normalize')
6
- const { normalizeCondition } = require('../utils/match-condition')
7
6
  const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
8
7
  const isEmptyObject = require('../utils/is-empty-object')
9
8
  const getRulesRunner = require('../platform/index')
@@ -1751,67 +1750,47 @@ function processBuiltInComponents (el, meta) {
1751
1750
  }
1752
1751
  }
1753
1752
 
1754
- function processAliAddComponentRootView (el, options) {
1755
- const processAttrsConditions = [
1756
- { condition: /^(on|catch)Tap$/, action: 'clone' },
1757
- { condition: /^(on|catch)TouchStart$/, action: 'clone' },
1758
- { condition: /^(on|catch)TouchMove$/, action: 'clone' },
1759
- { condition: /^(on|catch)TouchEnd$/, action: 'clone' },
1760
- { condition: /^(on|catch)TouchCancel$/, action: 'clone' },
1761
- { condition: /^(on|catch)LongTap$/, action: 'clone' },
1762
- { condition: /^data-/, action: 'clone' },
1763
- { condition: /^style$/, action: 'move' },
1764
- { condition: /^slot$/, action: 'move' }
1765
- ]
1766
- const processAppendAttrsRules = [
1767
- { name: 'class', value: `${MPX_ROOT_VIEW} host-${options.moduleId}` }
1768
- ]
1769
- const newElAttrs = []
1770
- const allAttrs = cloneAttrsList(el.attrsList)
1771
-
1772
- function processClone (attr) {
1773
- newElAttrs.push(attr)
1774
- }
1775
-
1776
- function processMove (attr) {
1777
- getAndRemoveAttr(el, attr.name)
1778
- newElAttrs.push(attr)
1753
+ function processRootViewEventHack (el, options, root) {
1754
+ // 只处理组件根节点
1755
+ if (!(options.isComponent && el === root && isRealNode(el))) {
1756
+ return
1779
1757
  }
1780
-
1781
- function processAppendRules (el) {
1782
- processAppendAttrsRules.forEach((rule) => {
1783
- const getNeedAppendAttrValue = el.attrsMap[rule.name]
1784
- const value = getNeedAppendAttrValue ? getNeedAppendAttrValue + ' ' + rule.value : rule.value
1785
- newElAttrs.push({
1786
- name: rule.name,
1787
- value
1788
- })
1758
+ const { proxyComponentEvents } = options
1759
+ if (proxyComponentEvents) {
1760
+ proxyComponentEvents.forEach((type) => {
1761
+ addAttrs(el, [{
1762
+ name: type,
1763
+ value: '__proxyEvent'
1764
+ }])
1789
1765
  })
1790
1766
  }
1767
+ }
1791
1768
 
1792
- processAttrsConditions.forEach(item => {
1793
- const matcher = normalizeCondition(item.condition)
1794
- allAttrs.forEach((attr) => {
1795
- if (matcher(attr.name)) {
1796
- if (item.action === 'clone') {
1797
- processClone(attr)
1798
- } else if (item.action === 'move') {
1799
- processMove(attr)
1800
- }
1769
+ function processRootViewStyleClassHack (el, options, root) {
1770
+ // 处理组件根节点
1771
+ if (options.isComponent && el === root && isRealNode(el)) {
1772
+ const processor = ({ name, value, typeName }) => {
1773
+ const sep = name === 'style' ? ';' : ' '
1774
+ value = value ? `{{${typeName}||''}}${sep}${value}` : `{{${typeName}||''}}`
1775
+ return [name, value]
1776
+ }
1777
+
1778
+ ['style', 'class'].forEach((type) => {
1779
+ const exp = getAndRemoveAttr(el, type).val
1780
+ const typeName = type === 'class' ? 'className' : type
1781
+ const [newName, newValue] = processor({
1782
+ name: type,
1783
+ value: exp,
1784
+ typeName
1785
+ })
1786
+ if (newValue !== undefined) {
1787
+ addAttrs(el, [{
1788
+ name: newName,
1789
+ value: newValue
1790
+ }])
1801
1791
  }
1802
1792
  })
1803
- })
1804
-
1805
- processAppendRules(el)
1806
- const componentWrapView = createASTElement('view', newElAttrs)
1807
- moveBaseDirective(componentWrapView, el)
1808
- if (el.is && el.components) {
1809
- el = postProcessComponentIs(el)
1810
1793
  }
1811
-
1812
- replaceNode(el, componentWrapView, true)
1813
- addChild(componentWrapView, el)
1814
- return componentWrapView
1815
1794
  }
1816
1795
 
1817
1796
  // 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
@@ -1823,17 +1802,18 @@ function getVirtualHostRoot (options, meta) {
1823
1802
  !meta.options && (meta.options = {})
1824
1803
  meta.options.virtualHost = true
1825
1804
  }
1826
- // if (mode === 'ali' && !options.hasVirtualHost) {
1827
- // // ali组件根节点实体化
1828
- // let rootView = createASTElement('view', [
1829
- // {
1830
- // name: 'class',
1831
- // value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
1832
- // }
1833
- // ])
1834
- // processElement(rootView, rootView, options, meta)
1835
- // return rootView
1836
- // }
1805
+ if ((mode === 'ali' || mode === 'web') && !options.hasVirtualHost) {
1806
+ // ali组件根节点实体化
1807
+ const rootView = createASTElement('view', [
1808
+ {
1809
+ name: 'class',
1810
+ value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
1811
+ }
1812
+ ])
1813
+ // 添加时间处理
1814
+ processElement(rootView, rootView, options, meta)
1815
+ return rootView
1816
+ }
1837
1817
  }
1838
1818
  return getTempNode()
1839
1819
  }
@@ -2012,6 +1992,16 @@ function processMpxTagName (el) {
2012
1992
  }
2013
1993
 
2014
1994
  function processElement (el, root, options, meta) {
1995
+ const transAli = mode === 'ali' && srcMode === 'wx'
1996
+ const transWeb = mode === 'web' && srcMode === 'wx'
1997
+ if (transAli) {
1998
+ processRootViewStyleClassHack(el, options, root)
1999
+ processRootViewEventHack(el, options, root)
2000
+ }
2001
+ if (transWeb) {
2002
+ processRootViewEventHack(el, options, root)
2003
+ }
2004
+
2015
2005
  processAtMode(el)
2016
2006
  // 如果已经标记了这个元素要被清除,直接return跳过后续处理步骤
2017
2007
  if (el._atModeStatus === 'mismatch') {
@@ -2031,8 +2021,6 @@ function processElement (el, root, options, meta) {
2031
2021
 
2032
2022
  processInjectWxs(el, meta)
2033
2023
 
2034
- const transAli = mode === 'ali' && srcMode === 'wx'
2035
-
2036
2024
  if (mode === 'web') {
2037
2025
  // 收集内建组件
2038
2026
  processBuiltInComponents(el, meta)
@@ -2084,11 +2072,7 @@ function closeElement (el, meta, options) {
2084
2072
  postProcessWxs(el, meta)
2085
2073
 
2086
2074
  if (!pass) {
2087
- if (isComponentNode(el, options) && !options.hasVirtualHost && mode === 'ali') {
2088
- el = processAliAddComponentRootView(el, options)
2089
- } else {
2090
- el = postProcessComponentIs(el)
2091
- }
2075
+ el = postProcessComponentIs(el)
2092
2076
  }
2093
2077
  postProcessFor(el)
2094
2078
  postProcessIf(el)
@@ -40,6 +40,14 @@ module.exports = function (raw) {
40
40
  )
41
41
  }
42
42
 
43
+ let proxyComponentEvents = null
44
+ for (const item of mpx.proxyComponentEventsRules) {
45
+ if (matchCondition(resourcePath, item)) {
46
+ const eventsRaw = item.events
47
+ proxyComponentEvents = Array.isArray(eventsRaw) ? eventsRaw : [eventsRaw]
48
+ break
49
+ }
50
+ }
43
51
  const { root: ast, meta } = compiler.parse(raw, {
44
52
  warn,
45
53
  error,
@@ -62,7 +70,8 @@ module.exports = function (raw) {
62
70
  checkUsingComponents: matchCondition(resourcePath, mpx.checkUsingComponentsRules),
63
71
  globalComponents: Object.keys(mpx.usingComponents),
64
72
  forceProxyEvent: matchCondition(resourcePath, mpx.forceProxyEventRules),
65
- hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules)
73
+ hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules),
74
+ proxyComponentEvents
66
75
  })
67
76
 
68
77
  if (meta.wxsContentMap) {
@@ -133,6 +142,10 @@ global.currentInject.getRefsData = function () {
133
142
  };\n`
134
143
  }
135
144
 
145
+ if (meta.options) {
146
+ resultSource += `global.currentInject.injectOptions = ${JSON.stringify(meta.options)};` + '\n'
147
+ }
148
+
136
149
  this.emitFile(resourcePath, '', undefined, {
137
150
  skipEmit: true,
138
151
  extractedResultSource: resultSource
@@ -182,8 +182,10 @@ module.exports = function (script, {
182
182
  pagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
183
183
  }
184
184
  }
185
-
186
- if (pageCfg.isFirst) {
185
+ if (pagePath === jsonConfig.entryPagePath) {
186
+ firstPage = pagePath
187
+ }
188
+ if (!firstPage && pageCfg.isFirst) {
187
189
  firstPage = pagePath
188
190
  }
189
191
  })
@@ -2,23 +2,7 @@ const templateCompiler = require('../template-compiler/compiler')
2
2
  const genComponentTag = require('../utils/gen-component-tag')
3
3
  const addQuery = require('../utils/add-query')
4
4
  const parseRequest = require('../utils/parse-request')
5
- // const { matchCondition } = require('../utils/match-condition')
6
-
7
- function calculateRootEleChild (arr) {
8
- if (!arr) {
9
- return 0
10
- }
11
- return arr.reduce((total, item) => {
12
- if (item.type === 1) {
13
- if (item.tag === 'template') {
14
- total += calculateRootEleChild(item.children)
15
- } else {
16
- total += 1
17
- }
18
- }
19
- return total
20
- }, 0)
21
- }
5
+ const { matchCondition } = require('../utils/match-condition')
22
6
 
23
7
  module.exports = function (template, {
24
8
  loaderContext,
@@ -38,8 +22,9 @@ module.exports = function (template, {
38
22
  wxsContentMap,
39
23
  decodeHTMLText,
40
24
  externalClasses,
41
- checkUsingComponents
42
- // autoVirtualHostRules
25
+ checkUsingComponents,
26
+ proxyComponentEventsRules,
27
+ autoVirtualHostRules
43
28
  } = mpx
44
29
  const { resourcePath } = parseRequest(loaderContext.resource)
45
30
  const builtInComponentsMap = {}
@@ -72,6 +57,16 @@ module.exports = function (template, {
72
57
  }
73
58
  if (template.content) {
74
59
  const templateSrcMode = template.mode || srcMode
60
+
61
+ let proxyComponentEvents = null
62
+ for (const item of proxyComponentEventsRules) {
63
+ if (matchCondition(resourcePath, item)) {
64
+ const eventsRaw = item.events
65
+ proxyComponentEvents = Array.isArray(eventsRaw) ? eventsRaw : [eventsRaw]
66
+ break
67
+ }
68
+ }
69
+
75
70
  const { root, meta } = templateCompiler.parse(template.content, {
76
71
  warn: (msg) => {
77
72
  loaderContext.emitWarning(
@@ -101,9 +96,9 @@ module.exports = function (template, {
101
96
  // web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
102
97
  globalComponents: [],
103
98
  // web模式下实现抽象组件
104
- componentGenerics
105
- // todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
106
- // hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules)
99
+ componentGenerics,
100
+ proxyComponentEvents,
101
+ hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules)
107
102
  })
108
103
  if (meta.wxsModuleMap) {
109
104
  wxsModuleMap = meta.wxsModuleMap
@@ -123,18 +118,6 @@ module.exports = function (template, {
123
118
  if (meta.genericsInfo) {
124
119
  genericsInfo = meta.genericsInfo
125
120
  }
126
- // 输出H5有多个root element时, 使用mpx-root-view标签包裹
127
- // todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
128
- if (root.tag === 'temp-node') {
129
- const childLen = calculateRootEleChild(root.children)
130
- if (childLen >= 2) {
131
- root.tag = 'div'
132
- templateCompiler.addAttrs(root, [{
133
- name: 'class',
134
- value: 'mpx-root-view'
135
- }])
136
- }
137
- }
138
121
  return templateCompiler.serialize(root)
139
122
  }
140
123
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.50",
3
+ "version": "2.8.51",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -81,5 +81,5 @@
81
81
  "engines": {
82
82
  "node": ">=14.14.0"
83
83
  },
84
- "gitHead": "32f30631cc5f37503fb7791cb3b0d6c901ee2b27"
84
+ "gitHead": "7b9523688cc1cf8077d8705e64ea5a742dccff13"
85
85
  }