@mpxjs/webpack-plugin 2.6.108 → 2.6.109

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.
@@ -25,23 +25,6 @@ export default function processOption (
25
25
  }
26
26
  }
27
27
 
28
- // 注册v-ex-classes自定义指令处理externalClasses
29
- Vue.directive('ex-classes', (el, binding, vnode) => {
30
- const context = vnode.context
31
- if (context) {
32
- const externalClasses = context.$options.externalClasses || []
33
- const classList = el.classList
34
- binding.value.forEach((className) => {
35
- const actualExternalClassNames = context.$attrs[className]
36
- if (externalClasses.indexOf(className) !== -1 && actualExternalClassNames) {
37
- classList.remove(className)
38
- actualExternalClassNames.split(/\s+/).forEach((actualExternalClassName) => {
39
- if (actualExternalClassName) classList.add(actualExternalClassName)
40
- })
41
- }
42
- })
43
- }
44
- })
45
28
  Vue.directive('animation', (el, binding) => {
46
29
  const newActions = binding && binding.value && binding.value.actions
47
30
  if (el.actions === newActions) {
@@ -1853,25 +1853,65 @@ function processAliExternalClassesHack (el, options) {
1853
1853
  }
1854
1854
  }
1855
1855
 
1856
+ // externalClasses只能模拟静态传递
1856
1857
  function processWebExternalClassesHack (el, options) {
1857
- // todo 处理scoped的情况, 处理组件多层传递externalClass的情况,通过externalClass属性传递实际类名及scopeId信息,可以使用特殊的类名形式代表scopeId,如#idstring
1858
- let staticClass = el.attrsMap['class']
1859
- let dynamicClass = el.attrsMap[':class']
1860
- if (staticClass || dynamicClass) {
1861
- const externalClasses = []
1858
+ const staticClass = getAndRemoveAttr(el, 'class').val
1859
+ if (staticClass) {
1860
+ const classNames = staticClass.split(/\s+/)
1861
+ const replacements = []
1862
1862
  options.externalClasses.forEach((className) => {
1863
- const reg = new RegExp('\\b' + className + '\\b')
1864
- if (reg.test(staticClass) || reg.test(dynamicClass)) {
1865
- externalClasses.push(className)
1863
+ const index = classNames.indexOf(className)
1864
+ if (index > -1) {
1865
+ replacements.push(`$attrs[${JSON.stringify(className)}]`)
1866
+ classNames.splice(index, 1)
1866
1867
  }
1867
1868
  })
1868
- if (externalClasses.length) {
1869
+
1870
+ if (classNames.length) {
1871
+ addAttrs(el, [{
1872
+ name: 'class',
1873
+ value: classNames.join(' ')
1874
+ }])
1875
+ }
1876
+
1877
+ if (replacements.length) {
1878
+ const dynamicClass = getAndRemoveAttr(el, ':class').val
1879
+ if (dynamicClass) replacements.push(dynamicClass)
1880
+
1869
1881
  addAttrs(el, [{
1870
- name: 'v-ex-classes',
1871
- value: JSON.stringify(externalClasses)
1882
+ name: ':class',
1883
+ value: `[${replacements.join(',')}]`
1872
1884
  }])
1873
1885
  }
1874
1886
  }
1887
+
1888
+ // 处理externalClasses多层透传
1889
+ const isComponent = isComponentNode(el, options)
1890
+ if (isComponent) {
1891
+ options.externalClasses.forEach((classLikeAttrName) => {
1892
+ let classLikeAttrValue = getAndRemoveAttr(el, classLikeAttrName).val
1893
+ if (classLikeAttrValue) {
1894
+ const classNames = classLikeAttrValue.split(/\s+/)
1895
+ const replacements = []
1896
+ options.externalClasses.forEach((className) => {
1897
+ const index = classNames.indexOf(className)
1898
+ if (index > -1) {
1899
+ replacements.push(`$attrs[${JSON.stringify(className)}]`)
1900
+ classNames.splice(index, 1)
1901
+ }
1902
+ })
1903
+
1904
+ if (classNames.length) {
1905
+ replacements.unshift(JSON.stringify(classNames.join(' ')))
1906
+ }
1907
+
1908
+ addAttrs(el, [{
1909
+ name: ':' + classLikeAttrName,
1910
+ value: `[${replacements.join(',')}].join(' ')`
1911
+ }])
1912
+ }
1913
+ })
1914
+ }
1875
1915
  }
1876
1916
 
1877
1917
  function processScoped (el, options) {
@@ -1909,7 +1949,7 @@ function processAliStyleClassHack (el, options, root) {
1909
1949
  processor = ({ name, value, typeName }) => {
1910
1950
  let sep = name === 'style' ? ';' : ' '
1911
1951
  value = value ? `{{${typeName}||''}}${sep}${value}` : `{{${typeName}||''}}`
1912
- return [ name, value ]
1952
+ return [name, value]
1913
1953
  }
1914
1954
  }
1915
1955
  // 非上述两种不处理
@@ -1931,6 +1971,7 @@ function processAliStyleClassHack (el, options, root) {
1931
1971
  }
1932
1972
  })
1933
1973
  }
1974
+
1934
1975
  // 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
1935
1976
  function getVirtualHostRoot (options, meta) {
1936
1977
  if (options.isComponent) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.6.108",
3
+ "version": "2.6.109",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -81,5 +81,5 @@
81
81
  "@types/babel-traverse": "^6.25.4",
82
82
  "@types/babel-types": "^7.0.4"
83
83
  },
84
- "gitHead": "5efa2dec1597b0b7dd45e46b3ddf23bf46e25177"
84
+ "gitHead": "1531292ee192d1af4d84e8aac8fa02afe5d92e24"
85
85
  }