@mpxjs/webpack-plugin 2.7.36 → 2.7.39

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
@@ -164,6 +164,12 @@ class MpxWebpackPlugin {
164
164
  }, options.nativeConfig)
165
165
  options.webConfig = options.webConfig || {}
166
166
  options.partialCompile = options.mode !== 'web' && options.partialCompile
167
+ let proxyComponentEventsRules = []
168
+ const proxyComponentEventsRulesRaw = options.proxyComponentEventsRules
169
+ if (proxyComponentEventsRulesRaw) {
170
+ proxyComponentEventsRules = Array.isArray(proxyComponentEventsRulesRaw) ? proxyComponentEventsRulesRaw : [proxyComponentEventsRulesRaw]
171
+ }
172
+ options.proxyComponentEventsRules = proxyComponentEventsRules
167
173
  this.options = options
168
174
  // Hack for buildDependencies
169
175
  const rawResolveBuildDependencies = FileSystemInfo.prototype.resolveBuildDependencies
@@ -568,6 +574,7 @@ class MpxWebpackPlugin {
568
574
  useRelativePath: this.options.useRelativePath,
569
575
  removedChunks: [],
570
576
  forceProxyEventRules: this.options.forceProxyEventRules,
577
+ proxyComponentEventsRules: this.options.proxyComponentEventsRules,
571
578
  pathHash: (resourcePath) => {
572
579
  if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
573
580
  return hash(path.relative(this.options.projectRoot, resourcePath))
@@ -863,7 +870,8 @@ class MpxWebpackPlugin {
863
870
  })
864
871
 
865
872
  JavascriptModulesPlugin.getCompilationHooks(compilation).renderStartup.tap('MpxWebpackPlugin', (source, module) => {
866
- if (module && mpx.exportModules.has(module)) {
873
+ const realModule = (module && module.rootModule) || module
874
+ if (realModule && mpx.exportModules.has(realModule)) {
867
875
  source = new ConcatSource(source)
868
876
  source.add('module.exports = __webpack_exports__;\n')
869
877
  }
@@ -1174,7 +1182,6 @@ class MpxWebpackPlugin {
1174
1182
  }
1175
1183
 
1176
1184
  const processedChunk = new Set()
1177
- const appName = mpx.appInfo.name
1178
1185
 
1179
1186
  function processChunk (chunk, isRuntime, relativeChunks) {
1180
1187
  const chunkFile = chunk.files.values().next().value
@@ -1198,7 +1205,7 @@ class MpxWebpackPlugin {
1198
1205
  // 引用runtime
1199
1206
  // 支付宝分包独立打包,通过全局context获取webpackJSONP
1200
1207
  if (mpx.mode === 'ali' && !mpx.isPluginMode) {
1201
- if (chunk.name === appName) {
1208
+ if (compilation.options.entry[chunk.name]) {
1202
1209
  // 在rootChunk中挂载jsonpCallback
1203
1210
  source.add('// process ali subpackages runtime in root chunk\n' +
1204
1211
  'var context = (function() { return this })() || Function("return this")();\n\n')
@@ -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')
@@ -11,6 +10,7 @@ const addQuery = require('../utils/add-query')
11
10
  const transDynamicClassExpr = require('./trans-dynamic-class-expr')
12
11
  const dash2hump = require('../utils/hump-dash').dash2hump
13
12
  const { inBrowser } = require('../utils/env')
13
+ const { matchCondition } = require('../utils/match-condition')
14
14
 
15
15
  /**
16
16
  * Make a map and return a function for checking if a key
@@ -746,7 +746,7 @@ function parse (template, options) {
746
746
  stack.push(element)
747
747
  } else {
748
748
  element.unary = true
749
- closeElement(element, meta, options)
749
+ closeElement(element, meta)
750
750
  }
751
751
  },
752
752
 
@@ -761,7 +761,7 @@ function parse (template, options) {
761
761
  // pop stack
762
762
  stack.pop()
763
763
  currentParent = stack[stack.length - 1]
764
- closeElement(element, meta, options)
764
+ closeElement(element, meta)
765
765
  }
766
766
  },
767
767
 
@@ -1813,67 +1813,57 @@ function processBuiltInComponents (el, meta) {
1813
1813
  }
1814
1814
  }
1815
1815
 
1816
- function processAliAddComponentRootView (el, options) {
1817
- const processAttrsConditions = [
1818
- { condition: /^(on|catch)Tap$/, action: 'clone' },
1819
- { condition: /^(on|catch)TouchStart$/, action: 'clone' },
1820
- { condition: /^(on|catch)TouchMove$/, action: 'clone' },
1821
- { condition: /^(on|catch)TouchEnd$/, action: 'clone' },
1822
- { condition: /^(on|catch)TouchCancel$/, action: 'clone' },
1823
- { condition: /^(on|catch)LongTap$/, action: 'clone' },
1824
- { condition: /^data-/, action: 'clone' },
1825
- { condition: /^style$/, action: 'move' },
1826
- { condition: /^slot$/, action: 'move' }
1827
- ]
1828
- const processAppendAttrsRules = [
1829
- { name: 'class', value: `${MPX_ROOT_VIEW} host-${options.moduleId}` }
1830
- ]
1831
- let newElAttrs = []
1832
- let allAttrs = cloneAttrsList(el.attrsList)
1833
-
1834
- function processClone (attr) {
1835
- newElAttrs.push(attr)
1816
+ function processAliEventHack (el, options, root) {
1817
+ // 只处理组件根节点
1818
+ if (!(options.isComponent && el === root && isRealNode(el))) {
1819
+ return
1836
1820
  }
1837
-
1838
- function processMove (attr) {
1839
- getAndRemoveAttr(el, attr.name)
1840
- newElAttrs.push(attr)
1821
+ const { proxyComponentEventsRules } = options
1822
+ let fallThroughEvents = ['onTap']
1823
+ // 判断当前文件是否在范围中
1824
+ const filePath = options.filePath
1825
+ for (let item of proxyComponentEventsRules) {
1826
+ const {
1827
+ include,
1828
+ exclude
1829
+ } = item || {}
1830
+
1831
+ if (matchCondition(filePath, {
1832
+ include,
1833
+ exclude
1834
+ })) {
1835
+ const eventsRaw = item.events
1836
+ const events = Array.isArray(eventsRaw) ? eventsRaw : [eventsRaw]
1837
+ fallThroughEvents = Array.from(new Set(fallThroughEvents.concat(events)))
1838
+ break
1839
+ }
1841
1840
  }
1842
1841
 
1843
- function processAppendRules (el) {
1844
- processAppendAttrsRules.forEach((rule) => {
1845
- const getNeedAppendAttrValue = el.attrsMap[rule.name]
1846
- const value = getNeedAppendAttrValue ? getNeedAppendAttrValue + ' ' + rule.value : rule.value
1847
- newElAttrs.push({
1848
- name: rule.name,
1849
- value
1850
- })
1851
- })
1852
- }
1842
+ fallThroughEvents.forEach((type) => {
1843
+ addAttrs(el, [{
1844
+ name: type,
1845
+ value: '__proxyEvent'
1846
+ }])
1847
+ })
1848
+ }
1853
1849
 
1854
- processAttrsConditions.forEach(item => {
1855
- const matcher = normalizeCondition(item.condition)
1856
- allAttrs.forEach((attr) => {
1857
- if (matcher(attr.name)) {
1858
- if (item.action === 'clone') {
1859
- processClone(attr)
1860
- } else if (item.action === 'move') {
1861
- processMove(attr)
1862
- }
1850
+ function processAliStyleClassHack (el, options, root) {
1851
+ // 处理组件根节点
1852
+ if (options.isComponent && el === root && isRealNode(el)) {
1853
+ ['style', 'class'].forEach((type) => {
1854
+ let exp = getAndRemoveAttr(el, type).val
1855
+ let typeName = type === 'class' ? 'className' : type
1856
+ let sep = type === 'style' ? ';' : ' '
1857
+ let newValue = exp ? `{{${typeName}||''}}${sep}${exp}` : `{{${typeName}||''}}`
1858
+
1859
+ if (newValue !== undefined) {
1860
+ addAttrs(el, [{
1861
+ name: type,
1862
+ value: newValue
1863
+ }])
1863
1864
  }
1864
1865
  })
1865
- })
1866
-
1867
- processAppendRules(el)
1868
- let componentWrapView = createASTElement('view', newElAttrs)
1869
- moveBaseDirective(componentWrapView, el)
1870
- if (el.is && el.components) {
1871
- el = postProcessComponentIs(el)
1872
1866
  }
1873
-
1874
- replaceNode(el, componentWrapView, true)
1875
- addChild(componentWrapView, el)
1876
- return componentWrapView
1877
1867
  }
1878
1868
 
1879
1869
  // 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
@@ -1885,36 +1875,36 @@ function getVirtualHostRoot (options, meta) {
1885
1875
  !meta.options && (meta.options = {})
1886
1876
  meta.options.virtualHost = true
1887
1877
  }
1888
- // if (mode === 'ali' && !options.hasVirtualHost) {
1889
- // // ali组件根节点实体化
1890
- // let rootView = createASTElement('view', [
1891
- // {
1892
- // name: 'class',
1893
- // value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
1894
- // }
1895
- // ])
1896
- // processElement(rootView, rootView, options, meta)
1897
- // return rootView
1898
- // }
1878
+ if (mode === 'ali' && !options.hasVirtualHost) {
1879
+ // ali组件根节点实体化
1880
+ let rootView = createASTElement('view', [
1881
+ {
1882
+ name: 'class',
1883
+ value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
1884
+ }
1885
+ ])
1886
+ processElement(rootView, rootView, options, meta)
1887
+ return rootView
1888
+ }
1899
1889
  }
1900
1890
  return getTempNode()
1901
1891
  }
1902
1892
 
1903
1893
  function processShow (el, options, root) {
1904
- // 开启 virtualhost 全部走 props 传递处理
1905
- // 未开启 virtualhost 直接绑定 display:none 到节点上
1906
1894
  let show = getAndRemoveAttr(el, config[mode].directive.show).val
1907
1895
  if (mode === 'swan') show = wrapMustache(show)
1908
-
1909
- if (options.hasVirtualHost) {
1910
- if (options.isComponent && el.parent === root && isRealNode(el)) {
1911
- if (show !== undefined) {
1912
- show = `{{${parseMustache(show).result}&&mpxShow}}`
1913
- } else {
1914
- show = '{{mpxShow}}'
1915
- }
1896
+ let processFlag = el.parent === root
1897
+ // 当ali且未开启virtualHost时,mpxShow打到根节点上
1898
+ if (mode === 'ali' && !options.hasVirtualHost) processFlag = el === root
1899
+ if (options.isComponent && processFlag && isRealNode(el)) {
1900
+ if (show !== undefined) {
1901
+ show = `{{${parseMustache(show).result}&&mpxShow}}`
1902
+ } else {
1903
+ show = '{{mpxShow}}'
1916
1904
  }
1917
- if (isComponentNode(el, options) && show !== undefined) {
1905
+ }
1906
+ if (show !== undefined) {
1907
+ if (isComponentNode(el, options)) {
1918
1908
  if (show === '') {
1919
1909
  show = '{{false}}'
1920
1910
  }
@@ -1923,14 +1913,6 @@ function processShow (el, options, root) {
1923
1913
  value: show
1924
1914
  }])
1925
1915
  } else {
1926
- processShowStyle()
1927
- }
1928
- } else {
1929
- processShowStyle()
1930
- }
1931
-
1932
- function processShowStyle () {
1933
- if (show !== undefined) {
1934
1916
  const showExp = parseMustache(show).result
1935
1917
  let oldStyle = getAndRemoveAttr(el, 'style').val
1936
1918
  oldStyle = oldStyle ? oldStyle + ';' : ''
@@ -2112,6 +2094,11 @@ function processElement (el, root, options, meta) {
2112
2094
  processShow(el, options, root)
2113
2095
  }
2114
2096
 
2097
+ if (transAli) {
2098
+ processAliStyleClassHack(el, options, root)
2099
+ processAliEventHack(el, options, root)
2100
+ }
2101
+
2115
2102
  if (!pass) {
2116
2103
  processBindEvent(el, options)
2117
2104
  processComponentIs(el, options)
@@ -2120,7 +2107,7 @@ function processElement (el, root, options, meta) {
2120
2107
  processAttrs(el, options)
2121
2108
  }
2122
2109
 
2123
- function closeElement (el, meta, options) {
2110
+ function closeElement (el, meta) {
2124
2111
  postProcessAtMode(el)
2125
2112
  if (mode === 'web') {
2126
2113
  postProcessWxs(el, meta)
@@ -2130,13 +2117,8 @@ function closeElement (el, meta, options) {
2130
2117
  }
2131
2118
  const pass = isNative || postProcessTemplate(el) || processingTemplate
2132
2119
  postProcessWxs(el, meta)
2133
-
2134
2120
  if (!pass) {
2135
- if (isComponentNode(el, options) && !options.hasVirtualHost && mode === 'ali') {
2136
- el = processAliAddComponentRootView(el, options)
2137
- } else {
2138
- el = postProcessComponentIs(el)
2139
- }
2121
+ el = postProcessComponentIs(el)
2140
2122
  }
2141
2123
  postProcessFor(el)
2142
2124
  postProcessIf(el)
@@ -59,7 +59,8 @@ module.exports = function (raw) {
59
59
  checkUsingComponents: mpx.checkUsingComponents,
60
60
  globalComponents: Object.keys(mpx.usingComponents),
61
61
  forceProxyEvent: matchCondition(resourcePath, mpx.forceProxyEventRules),
62
- hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules)
62
+ hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules),
63
+ proxyComponentEventsRules: mpx.proxyComponentEventsRules
63
64
  })
64
65
 
65
66
  if (meta.wxsContentMap) {
@@ -44,6 +44,15 @@ module.exports = function (content) {
44
44
  }
45
45
  }
46
46
  },
47
+ CallExpression (path) {
48
+ const callee = path.node.callee
49
+ if (t.isIdentifier(callee) && callee.name === 'getRegExp') {
50
+ const argPath = path.get('arguments')[0]
51
+ if (argPath.isStringLiteral()) {
52
+ argPath.replaceWith(t.stringLiteral(argPath.node.extra.raw.slice(1, -1)))
53
+ }
54
+ }
55
+ },
47
56
  ForStatement (path) {
48
57
  if (path.shouldStopTraverse) {
49
58
  path.stop()
@@ -92,12 +101,19 @@ module.exports = function (content) {
92
101
  },
93
102
  CallExpression (path) {
94
103
  const callee = path.node.callee
104
+ const args = path.node.arguments
95
105
  const transMap = {
96
106
  getDate: 'Date',
97
107
  getRegExp: 'RegExp'
98
108
  }
99
109
  if (t.isIdentifier(callee) && transMap[callee.name]) {
100
- path.replaceWith(t.newExpression(t.identifier(transMap[callee.name]), path.node.arguments))
110
+ if (callee.name === 'getRegExp') {
111
+ const arg = args[0]
112
+ if (t.isStringLiteral(arg)) {
113
+ args[0] = t.stringLiteral(arg.extra.raw.slice(1, -1))
114
+ }
115
+ }
116
+ path.replaceWith(t.newExpression(t.identifier(transMap[callee.name]), args))
101
117
  }
102
118
  }
103
119
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.7.36",
3
+ "version": "2.7.39",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -80,5 +80,5 @@
80
80
  "engines": {
81
81
  "node": ">=14.14.0"
82
82
  },
83
- "gitHead": "5838576bdde0b66664f8121c729143ff4ed0aef4"
83
+ "gitHead": "6431ec3444ca7625f07495c0d614ee77e8d654b0"
84
84
  }