@mpxjs/webpack-plugin 2.7.9 → 2.7.12

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.
@@ -95,7 +95,6 @@ class DynamicEntryDependency extends NullDependency {
95
95
  const { packageRoot, context } = this
96
96
  this.originEntryNode = mpx.getEntryNode(module)
97
97
  this.publicPath = compilation.outputOptions.publicPath || ''
98
- this.applied = false
99
98
  if (context) this.resolver = compilation.resolverFactory.get('normal', module.resolveOptions)
100
99
  // 分包构建在需要在主包构建完成后在finishMake中处理,返回的资源路径先用key来占位,在合成extractedAssets时再进行最终替换
101
100
  if (packageRoot && mpx.currentPackageRoot !== packageRoot) {
@@ -113,8 +112,10 @@ class DynamicEntryDependency extends NullDependency {
113
112
 
114
113
  // hash会影响最终的codeGenerateResult是否走缓存,由于该dep中resultPath是动态变更的,需要将其更新到hash中,避免错误使用缓存
115
114
  updateHash (hash, context) {
116
- const { resultPath } = this
115
+ const { resultPath, relativePath } = this
117
116
  if (resultPath) hash.update(resultPath)
117
+ // relativePath为MPX_CURRENT_CHUNK时,插入随机数hash使当前module的codeGeneration cache失效,以执行dep.apply动态获取当前module所属的chunk路径
118
+ if (relativePath === MPX_CURRENT_CHUNK) hash.update('' + Math.random())
118
119
  super.updateHash(hash, context)
119
120
  }
120
121
 
@@ -162,7 +163,6 @@ DynamicEntryDependency.Template = class DynamicEntryDependencyTemplate {
162
163
  const replaceRange = `mpx_replace_path_${key}`
163
164
  source.replace(range[0], range[1] - 1, JSON.stringify(replaceRange))
164
165
  }
165
- dep.applied = true
166
166
  }
167
167
  }
168
168
 
package/lib/index.js CHANGED
@@ -34,7 +34,7 @@ const RemoveEntryDependency = require('./dependencies/RemoveEntryDependency')
34
34
  const SplitChunksPlugin = require('webpack/lib/optimize/SplitChunksPlugin')
35
35
  const fixRelative = require('./utils/fix-relative')
36
36
  const parseRequest = require('./utils/parse-request')
37
- const matchCondition = require('./utils/match-condition')
37
+ const { matchCondition } = require('./utils/match-condition')
38
38
  const { preProcessDefs } = require('./utils/index')
39
39
  const config = require('./config')
40
40
  const hash = require('hash-sum')
@@ -407,8 +407,7 @@ class MpxWebpackPlugin {
407
407
  async.each(deps, (dep, callback) => {
408
408
  dep.addEntry(compilation, (err, { resultPath }) => {
409
409
  if (err) return callback(err)
410
- if (dep.applied) mpx.replacePathMap[dep.key] = resultPath
411
- dep.resultPath = resultPath
410
+ dep.resultPath = mpx.replacePathMap[dep.key] = resultPath
412
411
  callback()
413
412
  })
414
413
  }, callback)
@@ -1301,10 +1300,11 @@ try {
1301
1300
  let insertBeforeIndex = -1
1302
1301
  const info = typeLoaderProcessInfo[type]
1303
1302
  loaders.forEach((loader, index) => {
1304
- if (loader.loader.includes(info[0])) {
1303
+ const currentLoader = toPosix(loader.loader)
1304
+ if (currentLoader.includes(info[0])) {
1305
1305
  loader.loader = info[1]
1306
1306
  }
1307
- if (loader.loader.includes(info[1])) {
1307
+ if (currentLoader.includes(info[1])) {
1308
1308
  insertBeforeIndex = index
1309
1309
  }
1310
1310
  })
@@ -1344,13 +1344,13 @@ try {
1344
1344
 
1345
1345
  if (mpx.mode === 'web') {
1346
1346
  const mpxStyleOptions = queryObj.mpxStyleOptions
1347
- const firstLoader = (loaders[0] && loaders[0].loader) || ''
1347
+ const firstLoader = toPosix(loaders[0] && loaders[0].loader) || ''
1348
1348
  const isPitcherRequest = firstLoader.includes('vue-loader/lib/loaders/pitcher')
1349
1349
  let cssLoaderIndex = -1
1350
1350
  let vueStyleLoaderIndex = -1
1351
1351
  let mpxStyleLoaderIndex = -1
1352
1352
  loaders.forEach((loader, index) => {
1353
- const currentLoader = loader.loader
1353
+ const currentLoader = toPosix(loader.loader)
1354
1354
  if (currentLoader.includes('css-loader')) {
1355
1355
  cssLoaderIndex = index
1356
1356
  } else if (currentLoader.includes('vue-loader/lib/loaders/stylePostLoader')) {
package/lib/loader.js CHANGED
@@ -3,7 +3,7 @@ const parseComponent = require('./parser')
3
3
  const createHelpers = require('./helpers')
4
4
  const loaderUtils = require('loader-utils')
5
5
  const parseRequest = require('./utils/parse-request')
6
- const matchCondition = require('./utils/match-condition')
6
+ const { matchCondition } = require('./utils/match-condition')
7
7
  const fixUsingComponent = require('./utils/fix-using-component')
8
8
  const addQuery = require('./utils/add-query')
9
9
  const async = require('async')
@@ -5,7 +5,7 @@ const config = require('./config')
5
5
  const createHelpers = require('./helpers')
6
6
  const getJSONContent = require('./utils/get-json-content')
7
7
  const async = require('async')
8
- const matchCondition = require('./utils/match-condition')
8
+ const { matchCondition } = require('./utils/match-condition')
9
9
  const fixUsingComponent = require('./utils/fix-using-component')
10
10
  const { JSON_JS_EXT } = require('./utils/const')
11
11
 
@@ -2,7 +2,7 @@ const path = require('path')
2
2
  const stringifyQuery = require('../utils/stringify-query')
3
3
  const parseQuery = require('loader-utils').parseQuery
4
4
  const addInfix = require('../utils/add-infix')
5
- const matchCondition = require('../utils/match-condition')
5
+ const { matchCondition } = require('../utils/match-condition')
6
6
  const { JSON_JS_EXT } = require('../utils/const')
7
7
 
8
8
  module.exports = class AddEnvPlugin {
@@ -1,7 +1,7 @@
1
1
  const path = require('path')
2
2
  const stringifyQuery = require('../utils/stringify-query')
3
3
  const parseQuery = require('loader-utils').parseQuery
4
- const matchCondition = require('../utils/match-condition')
4
+ const { matchCondition } = require('../utils/match-condition')
5
5
  const addInfix = require('../utils/add-infix')
6
6
  const { JSON_JS_EXT } = require('../utils/const')
7
7
 
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import getInnerListeners from './getInnerListeners'
2
+ import getInnerListeners, { extendEvent } from './getInnerListeners'
3
3
 
4
4
  export default {
5
5
  name: 'mpx-image',
@@ -23,6 +23,13 @@
23
23
  beforeCreate () {
24
24
  this.image = new Image()
25
25
  this.image.onload = (e) => {
26
+ extendEvent(e, {
27
+ detail: {
28
+ width: this.image.width,
29
+ height: this.image.height
30
+ }
31
+ })
32
+
26
33
  this.$emit('load', e)
27
34
  }
28
35
  this.image.onerror = (e) => {
@@ -7,7 +7,7 @@ const vw = require('./plugins/vw')
7
7
  const pluginCondStrip = require('./plugins/conditional-strip')
8
8
  const scopeId = require('./plugins/scope-id')
9
9
  const transSpecial = require('./plugins/trans-special')
10
- const matchCondition = require('../utils/match-condition')
10
+ const { matchCondition } = require('../utils/match-condition')
11
11
  const parseRequest = require('../utils/parse-request')
12
12
 
13
13
  module.exports = function (css, map) {
@@ -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
-
14
14
  /**
15
15
  * Make a map and return a function for checking if a key
16
16
  * is in that map.
@@ -737,8 +737,10 @@ function parse (template, options) {
737
737
 
738
738
  currentParent.children.push(element)
739
739
  element.parent = currentParent
740
-
741
740
  processElement(element, root, options, meta)
741
+ if (isComponentNode(element, options) && mode === 'ali' && !options.hasVirtualHost) {
742
+ processAliAddComponentRootView(element, options, stack, currentParent)
743
+ }
742
744
  tagNames.add(element.tag)
743
745
 
744
746
  if (!unary) {
@@ -1800,36 +1802,70 @@ function processBuiltInComponents (el, meta) {
1800
1802
  }
1801
1803
  }
1802
1804
 
1803
- function processAliStyleClassHack (el, options, root) {
1804
- let processor
1805
- // 处理组件标签
1806
- if (isComponentNode(el, options)) processor = ({ value, typeName }) => [typeName, value]
1807
- // 处理组件根节点
1808
- if (options.isComponent && el === root && isRealNode(el)) {
1809
- processor = ({ name, value, typeName }) => {
1810
- let sep = name === 'style' ? ';' : ' '
1811
- value = value ? `{{${typeName}||''}}${sep}${value}` : `{{${typeName}||''}}`
1812
- return [name, value]
1805
+ function processAliAddComponentRootView (el, options, stack, currentParent) {
1806
+ const processAttrsConditions = [
1807
+ { condition: /^(on|catch)Tap$/, action: 'clone' },
1808
+ { condition: /^(on|catch)TouchStart$/, action: 'clone' },
1809
+ { condition: /^(on|catch)TouchMove$/, action: 'clone' },
1810
+ { condition: /^(on|catch)TouchEnd$/, action: 'clone' },
1811
+ { condition: /^(on|catch)TouchCancel$/, action: 'clone' },
1812
+ { condition: /^(on|catch)LongTap$/, action: 'clone' },
1813
+ { condition: /^data-/, action: 'clone' },
1814
+ { condition: 'style', action: 'move' },
1815
+ { condition: 'class', action: 'append', value: `${MPX_ROOT_VIEW} host-${options.moduleId}` }
1816
+ ]
1817
+ let newElAttrs = []
1818
+ let allAttrs = cloneAttrsList(el.attrsList)
1819
+
1820
+ function processClone (attr) {
1821
+ newElAttrs.push(attr)
1822
+ }
1823
+
1824
+ function processMove (attr) {
1825
+ let movedAttr = getAndRemoveAttr(el, attr.name)
1826
+ if (movedAttr.has) {
1827
+ newElAttrs.push({
1828
+ name: attr,
1829
+ value: movedAttr.val
1830
+ })
1813
1831
  }
1814
1832
  }
1815
- // 非上述两种不处理
1816
- if (!processor) return
1817
- // 处理style、class
1818
- ['style', 'class'].forEach((type) => {
1819
- let exp = getAndRemoveAttr(el, type).val
1820
- let typeName = 'mpx' + type.replace(/^./, (matched) => matched.toUpperCase())
1821
- let [newName, newValue] = processor({
1822
- name: type,
1823
- value: exp,
1824
- typeName
1825
- })
1826
- if (newValue !== undefined) {
1827
- addAttrs(el, [{
1828
- name: newName,
1829
- value: newValue
1830
- }])
1833
+
1834
+ function processAppend (attr, item) {
1835
+ const getNeedAppendAttrValue = el.attrsMap[attr.name]
1836
+ if (getNeedAppendAttrValue) {
1837
+ item.value = getNeedAppendAttrValue + ' ' + item.value
1831
1838
  }
1839
+ newElAttrs.push({
1840
+ name: attr.name,
1841
+ value: item.value
1842
+ })
1843
+ }
1844
+
1845
+ processAttrsConditions.forEach(item => {
1846
+ const matcher = normalizeCondition(item.condition)
1847
+ allAttrs.forEach((attr) => {
1848
+ if (matcher(attr.name)) {
1849
+ if (item.action === 'clone') {
1850
+ processClone(attr)
1851
+ } else if (item.action === 'move') {
1852
+ processMove(attr)
1853
+ } else if (item.action === 'append') {
1854
+ processAppend(attr, item)
1855
+ }
1856
+ }
1857
+ })
1832
1858
  })
1859
+
1860
+ // create new el
1861
+ 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
1867
+
1868
+ el = componentWrapView
1833
1869
  }
1834
1870
 
1835
1871
  // 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
@@ -1841,17 +1877,17 @@ function getVirtualHostRoot (options, meta) {
1841
1877
  !meta.options && (meta.options = {})
1842
1878
  meta.options.virtualHost = true
1843
1879
  }
1844
- if (mode === 'ali' && !options.hasVirtualHost) {
1845
- // ali组件根节点实体化
1846
- let rootView = createASTElement('view', [
1847
- {
1848
- name: 'class',
1849
- value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
1850
- }
1851
- ])
1852
- processElement(rootView, rootView, options, meta)
1853
- return rootView
1854
- }
1880
+ // if (mode === 'ali' && !options.hasVirtualHost) {
1881
+ // // ali组件根节点实体化
1882
+ // let rootView = createASTElement('view', [
1883
+ // {
1884
+ // name: 'class',
1885
+ // value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
1886
+ // }
1887
+ // ])
1888
+ // processElement(rootView, rootView, options, meta)
1889
+ // return rootView
1890
+ // }
1855
1891
  }
1856
1892
  return getTempNode()
1857
1893
  }
@@ -2060,11 +2096,6 @@ function processElement (el, root, options, meta) {
2060
2096
  processShow(el, options, root)
2061
2097
  }
2062
2098
 
2063
- // 当mode为ali不管是不是跨平台都需要进行此处理,以保障ali当中的refs相关增强能力正常运行
2064
- if (mode === 'ali') {
2065
- processAliStyleClassHack(el, options, root)
2066
- }
2067
-
2068
2099
  if (!pass) {
2069
2100
  processBindEvent(el, options)
2070
2101
  processComponentIs(el, options)
@@ -1,7 +1,7 @@
1
1
  const compiler = require('./compiler')
2
2
  const bindThis = require('./bind-this').transform
3
3
  const parseRequest = require('../utils/parse-request')
4
- const matchCondition = require('../utils/match-condition')
4
+ const { matchCondition } = require('../utils/match-condition')
5
5
  const loaderUtils = require('loader-utils')
6
6
 
7
7
  module.exports = function (raw) {
@@ -45,4 +45,7 @@ const matchCondition = (resourcePath, condition = {}) => {
45
45
  return matched
46
46
  }
47
47
 
48
- module.exports = matchCondition
48
+ module.exports = {
49
+ matchCondition,
50
+ normalizeCondition
51
+ }
@@ -2,8 +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
-
6
- // const matchCondition = require('../utils/match-condition')
5
+ // const { matchCondition } = require('../utils/match-condition')
7
6
 
8
7
  function calculateRootEleChild (arr) {
9
8
  if (!arr) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.7.9",
3
+ "version": "2.7.12",
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": "43b560f84b8e40563c84ef1dc0e4a7d3b4730d93"
83
+ "gitHead": "5917df99372acfdca21ce770cb8bf8f780974311"
84
84
  }