@mpxjs/webpack-plugin 2.7.12 → 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
@@ -11,6 +11,7 @@ const CommonJsAsyncDependency = require('./dependencies/CommonJsAsyncDependency'
11
11
  const NormalModule = require('webpack/lib/NormalModule')
12
12
  const EntryPlugin = require('webpack/lib/EntryPlugin')
13
13
  const JavascriptModulesPlugin = require('webpack/lib/javascript/JavascriptModulesPlugin')
14
+ const FileSystemInfo = require('webpack/lib/FileSystemInfo')
14
15
  const normalize = require('./utils/normalize')
15
16
  const toPosix = require('./utils/to-posix')
16
17
  const addQuery = require('./utils/add-query')
@@ -159,6 +160,14 @@ class MpxWebpackPlugin {
159
160
  }, options.nativeConfig)
160
161
  options.webConfig = options.webConfig || {}
161
162
  this.options = options
163
+ // Hack for buildDependencies
164
+ const rawResolveBuildDependencies = FileSystemInfo.prototype.resolveBuildDependencies
165
+ FileSystemInfo.prototype.resolveBuildDependencies = function (context, deps, rawCallback) {
166
+ return rawResolveBuildDependencies.call(this, context, deps, (err, result) => {
167
+ if (result && typeof options.hackResolveBuildDependencies === 'function') options.hackResolveBuildDependencies(result)
168
+ return rawCallback(err, result)
169
+ })
170
+ }
162
171
  }
163
172
 
164
173
  static loader (options = {}) {
@@ -1121,6 +1130,17 @@ class MpxWebpackPlugin {
1121
1130
  }, () => {
1122
1131
  if (mpx.mode === 'web') return
1123
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
+ const filename = this.options.generateBuildMap.filename || 'outputMap.json'
1141
+ compilation.assets[filename] = new RawSource(outputMap)
1142
+ }
1143
+
1124
1144
  const {
1125
1145
  globalObject,
1126
1146
  chunkLoadingGlobal
@@ -1303,8 +1323,8 @@ try {
1303
1323
  const currentLoader = toPosix(loader.loader)
1304
1324
  if (currentLoader.includes(info[0])) {
1305
1325
  loader.loader = info[1]
1306
- }
1307
- if (currentLoader.includes(info[1])) {
1326
+ insertBeforeIndex = index
1327
+ } else if (currentLoader.includes(info[1])) {
1308
1328
  insertBeforeIndex = index
1309
1329
  }
1310
1330
  })
@@ -1344,7 +1364,7 @@ try {
1344
1364
 
1345
1365
  if (mpx.mode === 'web') {
1346
1366
  const mpxStyleOptions = queryObj.mpxStyleOptions
1347
- const firstLoader = toPosix(loaders[0] && loaders[0].loader) || ''
1367
+ const firstLoader = loaders[0] ? toPosix(loaders[0].loader) : ''
1348
1368
  const isPitcherRequest = firstLoader.includes('vue-loader/lib/loaders/pitcher')
1349
1369
  let cssLoaderIndex = -1
1350
1370
  let vueStyleLoaderIndex = -1
@@ -1381,25 +1401,6 @@ try {
1381
1401
  })
1382
1402
  })
1383
1403
 
1384
- compiler.hooks.emit.tap('MpxWebpackPlugin', (compilation) => {
1385
- if (this.options.generateBuildMap) {
1386
- const pagesMap = compilation.__mpx__.pagesMap
1387
- const componentsPackageMap = compilation.__mpx__.componentsMap
1388
- const componentsMap = Object.keys(componentsPackageMap).map(item => componentsPackageMap[item]).reduce((pre, cur) => {
1389
- return { ...pre, ...cur }
1390
- }, {})
1391
- const outputMap = JSON.stringify({ ...pagesMap, ...componentsMap })
1392
- compilation.assets['../outputMap.json'] = {
1393
- source: () => {
1394
- return outputMap
1395
- },
1396
- size: () => {
1397
- return Buffer.byteLength(outputMap, 'utf8')
1398
- }
1399
- }
1400
- }
1401
- })
1402
-
1403
1404
  const clearFileCache = () => {
1404
1405
  const fs = compiler.intermediateFileSystem
1405
1406
  const cacheLocation = compiler.options.cache.cacheLocation
@@ -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
  })
@@ -16,7 +16,9 @@ module.exports = function loadPostcssConfig (loaderContext, inlineConfig = {}) {
16
16
  webpack: loaderContext,
17
17
  defs: inlineConfig.defs || {}
18
18
  }
19
- loaded = load(ctx, config.path, { argv: false }).catch(err => {
19
+ loaded = load(ctx, config.path, {
20
+ loaders: { '.json': (_, content) => JSON.parse(content) }
21
+ }).catch(err => {
20
22
  // postcss-load-config throws error when no config file is found,
21
23
  // but for us it's optional. only emit other errors
22
24
  if (err.message.indexOf('No PostCSS Config found') >= 0) {
@@ -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.12",
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": "5917df99372acfdca21ce770cb8bf8f780974311"
83
+ "gitHead": "bf6b0d9938fecb4faafa2557c2c2caad1ea98535"
84
84
  }