@mpxjs/webpack-plugin 2.7.14 → 2.7.15

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
@@ -130,7 +130,7 @@ class MpxWebpackPlugin {
130
130
  })
131
131
  // 批量指定源码mode
132
132
  options.modeRules = options.modeRules || {}
133
- // options.generateBuildMap = options.generateBuildMap || false
133
+ options.generateBuildMap = options.generateBuildMap || false
134
134
  options.attributes = options.attributes || []
135
135
  options.externals = (options.externals || []).map((external) => {
136
136
  return externalsMap[external] || external
@@ -1130,22 +1130,16 @@ class MpxWebpackPlugin {
1130
1130
  }, () => {
1131
1131
  if (mpx.mode === 'web') return
1132
1132
 
1133
- // if (this.options.generateBuildMap) {
1134
- // const pagesMap = compilation.__mpx__.pagesMap
1135
- // const componentsPackageMap = compilation.__mpx__.componentsMap
1136
- // const componentsMap = Object.keys(componentsPackageMap).map(item => componentsPackageMap[item]).reduce((pre, cur) => {
1137
- // return { ...pre, ...cur }
1138
- // }, {})
1139
- // const outputMap = JSON.stringify({ ...pagesMap, ...componentsMap })
1140
- // compilation.assets['../outputMap.json'] = {
1141
- // source: () => {
1142
- // return outputMap
1143
- // },
1144
- // size: () => {
1145
- // return Buffer.byteLength(outputMap, 'utf8')
1146
- // }
1147
- // }
1148
- // }
1133
+ if (this.options.generateBuildMap) {
1134
+ const pagesMap = compilation.__mpx__.pagesMap
1135
+ const componentsPackageMap = compilation.__mpx__.componentsMap
1136
+ const componentsMap = Object.keys(componentsPackageMap).map(item => componentsPackageMap[item]).reduce((pre, cur) => {
1137
+ return { ...pre, ...cur }
1138
+ }, {})
1139
+ const outputMap = JSON.stringify({ ...pagesMap, ...componentsMap })
1140
+ const filename = this.options.generateBuildMap.filename || 'outputMap.json'
1141
+ compilation.assets[filename] = new RawSource(outputMap)
1142
+ }
1149
1143
 
1150
1144
  const {
1151
1145
  globalObject,
@@ -246,7 +246,7 @@ module.exports = function getSpec ({ warn, error }) {
246
246
  jd: deletePath()
247
247
  },
248
248
  {
249
- test: 'navigateToMiniProgramAppIdList|networkTimeout|permission',
249
+ test: 'navigateToMiniProgramAppIdList|networkTimeout',
250
250
  ali: deletePath(),
251
251
  jd: deletePath()
252
252
  },
@@ -4,7 +4,7 @@ const runRules = require('../run-rules')
4
4
  * @desc 针对每一个组件(属性,event,指令等)执行规则判断
5
5
  * @params cfgs [{test: 'camera', props:[], event: []}] 组件配置列表
6
6
  * @params spec ../index.js中公共的spec
7
- */
7
+ */
8
8
  module.exports = function normalizeComponentRules (cfgs, spec) {
9
9
  return cfgs.map((cfg) => {
10
10
  const result = {}
@@ -25,9 +25,8 @@ module.exports = function normalizeComponentRules (cfgs, spec) {
25
25
  data
26
26
  }
27
27
  el.attrsList.forEach((attr) => {
28
- let rAttr = runRules(spec.preAttrs, attr, options)
29
28
  const meta = {}
30
- rAttr = runRules(spec.directive, rAttr, {
29
+ let rAttr = runRules(spec.directive, attr, {
31
30
  ...options,
32
31
  meta
33
32
  })
@@ -11,6 +11,7 @@ const addQuery = require('../utils/add-query')
11
11
  const transDynamicClassExpr = require('./trans-dynamic-class-expr')
12
12
  const dash2hump = require('../utils/hump-dash').dash2hump
13
13
  const { inBrowser } = require('../utils/env')
14
+
14
15
  /**
15
16
  * Make a map and return a function for checking if a key
16
17
  * is in that map.
@@ -738,9 +739,6 @@ function parse (template, options) {
738
739
  currentParent.children.push(element)
739
740
  element.parent = currentParent
740
741
  processElement(element, root, options, meta)
741
- if (isComponentNode(element, options) && mode === 'ali' && !options.hasVirtualHost) {
742
- processAliAddComponentRootView(element, options, stack, currentParent)
743
- }
744
742
  tagNames.add(element.tag)
745
743
 
746
744
  if (!unary) {
@@ -748,7 +746,7 @@ function parse (template, options) {
748
746
  stack.push(element)
749
747
  } else {
750
748
  element.unary = true
751
- closeElement(element, meta)
749
+ closeElement(element, meta, options)
752
750
  }
753
751
  },
754
752
 
@@ -763,7 +761,7 @@ function parse (template, options) {
763
761
  // pop stack
764
762
  stack.pop()
765
763
  currentParent = stack[stack.length - 1]
766
- closeElement(element, meta)
764
+ closeElement(element, meta, options)
767
765
  }
768
766
  },
769
767
 
@@ -906,6 +904,19 @@ function modifyAttr (el, name, val) {
906
904
  }
907
905
  }
908
906
 
907
+ function moveBaseDirective (target, from, isDelete = true) {
908
+ target.for = from.for
909
+ target.if = from.if
910
+ target.elseif = from.elseif
911
+ target.else = from.else
912
+ if (isDelete) {
913
+ delete from.for
914
+ delete from.if
915
+ delete from.elseif
916
+ delete from.else
917
+ }
918
+ }
919
+
909
920
  function stringify (str) {
910
921
  return JSON.stringify(str)
911
922
  }
@@ -1802,7 +1813,7 @@ function processBuiltInComponents (el, meta) {
1802
1813
  }
1803
1814
  }
1804
1815
 
1805
- function processAliAddComponentRootView (el, options, stack, currentParent) {
1816
+ function processAliAddComponentRootView (el, options) {
1806
1817
  const processAttrsConditions = [
1807
1818
  { condition: /^(on|catch)Tap$/, action: 'clone' },
1808
1819
  { condition: /^(on|catch)TouchStart$/, action: 'clone' },
@@ -1811,8 +1822,10 @@ function processAliAddComponentRootView (el, options, stack, currentParent) {
1811
1822
  { condition: /^(on|catch)TouchCancel$/, action: 'clone' },
1812
1823
  { condition: /^(on|catch)LongTap$/, action: 'clone' },
1813
1824
  { condition: /^data-/, action: 'clone' },
1814
- { condition: 'style', action: 'move' },
1815
- { condition: 'class', action: 'append', value: `${MPX_ROOT_VIEW} host-${options.moduleId}` }
1825
+ { condition: 'style', action: 'move' }
1826
+ ]
1827
+ const processAppendAttrsRules = [
1828
+ { name: 'class', value: `${MPX_ROOT_VIEW} host-${options.moduleId}` }
1816
1829
  ]
1817
1830
  let newElAttrs = []
1818
1831
  let allAttrs = cloneAttrsList(el.attrsList)
@@ -1831,14 +1844,14 @@ function processAliAddComponentRootView (el, options, stack, currentParent) {
1831
1844
  }
1832
1845
  }
1833
1846
 
1834
- function processAppend (attr, item) {
1835
- const getNeedAppendAttrValue = el.attrsMap[attr.name]
1836
- if (getNeedAppendAttrValue) {
1837
- item.value = getNeedAppendAttrValue + ' ' + item.value
1838
- }
1839
- newElAttrs.push({
1840
- name: attr.name,
1841
- value: item.value
1847
+ function processAppendRules (el) {
1848
+ processAppendAttrsRules.forEach((rule) => {
1849
+ const getNeedAppendAttrValue = el.attrsMap[rule.name]
1850
+ const value = getNeedAppendAttrValue ? getNeedAppendAttrValue + ' ' + rule.value : rule.value
1851
+ newElAttrs.push({
1852
+ name: rule.name,
1853
+ value
1854
+ })
1842
1855
  })
1843
1856
  }
1844
1857
 
@@ -1850,22 +1863,21 @@ function processAliAddComponentRootView (el, options, stack, currentParent) {
1850
1863
  processClone(attr)
1851
1864
  } else if (item.action === 'move') {
1852
1865
  processMove(attr)
1853
- } else if (item.action === 'append') {
1854
- processAppend(attr, item)
1855
1866
  }
1856
1867
  }
1857
1868
  })
1858
1869
  })
1859
1870
 
1860
- // create new el
1871
+ processAppendRules(el)
1861
1872
  let componentWrapView = createASTElement('view', newElAttrs)
1862
- currentParent.children.pop()
1863
- currentParent.children.push(componentWrapView)
1864
- componentWrapView.parent = currentParent
1865
- componentWrapView.children.push(el)
1866
- el.parent = componentWrapView
1873
+ moveBaseDirective(componentWrapView, el)
1874
+ if (el.is && el.components) {
1875
+ el = postProcessComponentIs(el)
1876
+ }
1867
1877
 
1868
- el = componentWrapView
1878
+ replaceNode(el, componentWrapView, true)
1879
+ addChild(componentWrapView, el)
1880
+ return componentWrapView
1869
1881
  }
1870
1882
 
1871
1883
  // 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
@@ -2104,7 +2116,7 @@ function processElement (el, root, options, meta) {
2104
2116
  processAttrs(el, options)
2105
2117
  }
2106
2118
 
2107
- function closeElement (el, meta) {
2119
+ function closeElement (el, meta, options) {
2108
2120
  postProcessAtMode(el)
2109
2121
  if (mode === 'web') {
2110
2122
  postProcessWxs(el, meta)
@@ -2114,8 +2126,13 @@ function closeElement (el, meta) {
2114
2126
  }
2115
2127
  const pass = isNative || postProcessTemplate(el) || processingTemplate
2116
2128
  postProcessWxs(el, meta)
2129
+
2117
2130
  if (!pass) {
2118
- el = postProcessComponentIs(el)
2131
+ if (isComponentNode(el, options) && !options.hasVirtualHost && mode === 'ali') {
2132
+ el = processAliAddComponentRootView(el, options)
2133
+ } else {
2134
+ el = postProcessComponentIs(el)
2135
+ }
2119
2136
  }
2120
2137
  postProcessFor(el)
2121
2138
  postProcessIf(el)
@@ -2154,10 +2171,7 @@ function postProcessComponentIs (el) {
2154
2171
  let tempNode
2155
2172
  if (el.for || el.if || el.elseif || el.else) {
2156
2173
  tempNode = createASTElement('block', [])
2157
- tempNode.for = el.for
2158
- tempNode.if = el.if
2159
- tempNode.elseif = el.elseif
2160
- tempNode.else = el.else
2174
+ moveBaseDirective(tempNode, el)
2161
2175
  } else {
2162
2176
  tempNode = getTempNode()
2163
2177
  }
@@ -2183,7 +2197,7 @@ function postProcessComponentIs (el) {
2183
2197
  if (!el.parent) {
2184
2198
  error$1('Dynamic component can not be the template root, considering wrapping it with <view> or <text> tag!')
2185
2199
  } else {
2186
- el = replaceNode(el, tempNode) || el
2200
+ el = replaceNode(el, tempNode, true) || el
2187
2201
  }
2188
2202
  }
2189
2203
  return el
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.7.14",
3
+ "version": "2.7.15",
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": "6490248041554fc3b6ffbe5a3acdb6f94d12331b"
83
+ "gitHead": "bf6b0d9938fecb4faafa2557c2c2caad1ea98535"
84
84
  }