@mpxjs/webpack-plugin 2.7.42 → 2.7.43

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,12 +164,6 @@ 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
173
167
  this.options = options
174
168
  // Hack for buildDependencies
175
169
  const rawResolveBuildDependencies = FileSystemInfo.prototype.resolveBuildDependencies
@@ -574,7 +568,6 @@ class MpxWebpackPlugin {
574
568
  useRelativePath: this.options.useRelativePath,
575
569
  removedChunks: [],
576
570
  forceProxyEventRules: this.options.forceProxyEventRules,
577
- proxyComponentEventsRules: this.options.proxyComponentEventsRules,
578
571
  pathHash: (resourcePath) => {
579
572
  if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
580
573
  return hash(path.relative(this.options.projectRoot, resourcePath))
package/lib/loader.js CHANGED
@@ -126,11 +126,12 @@ module.exports = function (content) {
126
126
  if (mode === 'web') {
127
127
  if (ctorType === 'app' && !queryObj.isApp) {
128
128
  const request = addQuery(this.resource, { isApp: true })
129
+ const el = mpx.webConfig.el || '#app'
129
130
  output += `
130
131
  import App from ${stringifyRequest(request)}
131
132
  import Vue from 'vue'
132
133
  new Vue({
133
- el: '#app',
134
+ el: '${el}',
134
135
  render: function(h){
135
136
  return h(App)
136
137
  }
@@ -1,5 +1,5 @@
1
1
  import { isEmptyObject } from './util'
2
- const isTouchDevice = 'ontouchstart' in document.documentElement
2
+ const isTouchDevice = document && ('ontouchstart' in document.documentElement)
3
3
 
4
4
  function processModel (listeners, context) {
5
5
  // 该函数只有wx:model的情况下才调用,而且默认e.detail.value有值
@@ -3,6 +3,7 @@ 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')
6
7
  const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
7
8
  const isEmptyObject = require('../utils/is-empty-object')
8
9
  const getRulesRunner = require('../platform/index')
@@ -10,7 +11,6 @@ const addQuery = require('../utils/add-query')
10
11
  const transDynamicClassExpr = require('./trans-dynamic-class-expr')
11
12
  const dash2hump = require('../utils/hump-dash').dash2hump
12
13
  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)
749
+ closeElement(element, meta, options)
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)
764
+ closeElement(element, meta, options)
765
765
  }
766
766
  },
767
767
 
@@ -1813,57 +1813,67 @@ function processBuiltInComponents (el, meta) {
1813
1813
  }
1814
1814
  }
1815
1815
 
1816
- function processAliEventHack (el, options, root) {
1817
- // 只处理组件根节点
1818
- if (!(options.isComponent && el === root && isRealNode(el))) {
1819
- return
1820
- }
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
- }
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)
1840
1836
  }
1841
1837
 
1842
- fallThroughEvents.forEach((type) => {
1843
- addAttrs(el, [{
1844
- name: type,
1845
- value: '__proxyEvent'
1846
- }])
1847
- })
1848
- }
1838
+ function processMove (attr) {
1839
+ getAndRemoveAttr(el, attr.name)
1840
+ newElAttrs.push(attr)
1841
+ }
1849
1842
 
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}||''}}`
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
+ }
1858
1853
 
1859
- if (newValue !== undefined) {
1860
- addAttrs(el, [{
1861
- name: type,
1862
- value: newValue
1863
- }])
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
+ }
1864
1863
  }
1865
1864
  })
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)
1866
1872
  }
1873
+
1874
+ replaceNode(el, componentWrapView, true)
1875
+ addChild(componentWrapView, el)
1876
+ return componentWrapView
1867
1877
  }
1868
1878
 
1869
1879
  // 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
@@ -1875,36 +1885,36 @@ function getVirtualHostRoot (options, meta) {
1875
1885
  !meta.options && (meta.options = {})
1876
1886
  meta.options.virtualHost = true
1877
1887
  }
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
- }
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
+ // }
1889
1899
  }
1890
1900
  return getTempNode()
1891
1901
  }
1892
1902
 
1893
1903
  function processShow (el, options, root) {
1904
+ // 开启 virtualhost 全部走 props 传递处理
1905
+ // 未开启 virtualhost 直接绑定 display:none 到节点上
1894
1906
  let show = getAndRemoveAttr(el, config[mode].directive.show).val
1895
1907
  if (mode === 'swan') show = wrapMustache(show)
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}}'
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
+ }
1904
1916
  }
1905
- }
1906
- if (show !== undefined) {
1907
- if (isComponentNode(el, options)) {
1917
+ if (isComponentNode(el, options) && show !== undefined) {
1908
1918
  if (show === '') {
1909
1919
  show = '{{false}}'
1910
1920
  }
@@ -1913,6 +1923,14 @@ function processShow (el, options, root) {
1913
1923
  value: show
1914
1924
  }])
1915
1925
  } else {
1926
+ processShowStyle()
1927
+ }
1928
+ } else {
1929
+ processShowStyle()
1930
+ }
1931
+
1932
+ function processShowStyle () {
1933
+ if (show !== undefined) {
1916
1934
  const showExp = parseMustache(show).result
1917
1935
  let oldStyle = getAndRemoveAttr(el, 'style').val
1918
1936
  oldStyle = oldStyle ? oldStyle + ';' : ''
@@ -2094,11 +2112,6 @@ function processElement (el, root, options, meta) {
2094
2112
  processShow(el, options, root)
2095
2113
  }
2096
2114
 
2097
- if (transAli || (srcMode === 'ali' && mode === 'ali')) {
2098
- processAliStyleClassHack(el, options, root)
2099
- processAliEventHack(el, options, root)
2100
- }
2101
-
2102
2115
  if (!pass) {
2103
2116
  processBindEvent(el, options)
2104
2117
  processComponentIs(el, options)
@@ -2107,7 +2120,7 @@ function processElement (el, root, options, meta) {
2107
2120
  processAttrs(el, options)
2108
2121
  }
2109
2122
 
2110
- function closeElement (el, meta) {
2123
+ function closeElement (el, meta, options) {
2111
2124
  postProcessAtMode(el)
2112
2125
  if (mode === 'web') {
2113
2126
  postProcessWxs(el, meta)
@@ -2117,8 +2130,13 @@ function closeElement (el, meta) {
2117
2130
  }
2118
2131
  const pass = isNative || postProcessTemplate(el) || processingTemplate
2119
2132
  postProcessWxs(el, meta)
2133
+
2120
2134
  if (!pass) {
2121
- el = postProcessComponentIs(el)
2135
+ if (isComponentNode(el, options) && !options.hasVirtualHost && mode === 'ali') {
2136
+ el = processAliAddComponentRootView(el, options)
2137
+ } else {
2138
+ el = postProcessComponentIs(el)
2139
+ }
2122
2140
  }
2123
2141
  postProcessFor(el)
2124
2142
  postProcessIf(el)
@@ -59,8 +59,7 @@ 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),
63
- proxyComponentEventsRules: mpx.proxyComponentEventsRules
62
+ hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules)
64
63
  })
65
64
 
66
65
  if (meta.wxsContentMap) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.7.42",
3
+ "version": "2.7.43",
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": "c93b582d76ccf1a0cd9ee073d12e436600e2f37d"
83
+ "gitHead": "9ba777d5b52c8a2f802c47c2dc10c6984deff1d8"
84
84
  }