@mpxjs/webpack-plugin 2.9.30 → 2.9.32

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.
@@ -7,6 +7,11 @@ class CommonJsExtractDependency extends ModuleDependency {
7
7
  this.range = range
8
8
  }
9
9
 
10
+ updateHash (hash, context) {
11
+ hash.update(this.weak + '')
12
+ super.updateHash(hash, context)
13
+ }
14
+
10
15
  get type () {
11
16
  return 'mpx cjs extract'
12
17
  }
package/lib/index.js CHANGED
@@ -302,7 +302,7 @@ class MpxWebpackPlugin {
302
302
  warnings.push(`webpack options: MpxWebpackPlugin accept options.output.filename to be ${outputFilename} only, custom options.output.filename will be ignored!`)
303
303
  }
304
304
  compiler.options.output.filename = compiler.options.output.chunkFilename = outputFilename
305
- if (this.options.optimizeSize) {
305
+ if (this.options.optimizeSize && isProductionLikeMode(compiler.options)) {
306
306
  compiler.options.optimization.chunkIds = 'total-size'
307
307
  compiler.options.optimization.moduleIds = 'natural'
308
308
  compiler.options.optimization.mangleExports = 'size'
@@ -964,17 +964,20 @@ class MpxWebpackPlugin {
964
964
  })
965
965
 
966
966
  compilation.hooks.finishModules.tap('MpxWebpackPlugin', (modules) => {
967
- // 移除extractor抽取后的空模块
968
- for (const module of modules) {
969
- if (module.buildInfo.isEmpty) {
970
- for (const connection of moduleGraph.getIncomingConnections(module)) {
971
- if (connection.dependency.type === 'mpx cjs extract') {
972
- connection.weak = true
973
- connection.dependency.weak = true
967
+ // 移除extractor抽取后的空模块,只有生产模式且optimizeSize设置为true时开启
968
+ if (this.options.optimizeSize && isProductionLikeMode(compiler.options)) {
969
+ for (const module of modules) {
970
+ if (module.buildInfo.isEmpty) {
971
+ for (const connection of moduleGraph.getIncomingConnections(module)) {
972
+ if (connection.dependency.type === 'mpx cjs extract') {
973
+ connection.weak = true
974
+ connection.dependency.weak = true
975
+ }
974
976
  }
975
977
  }
976
978
  }
977
979
  }
980
+
978
981
  // 自动使用分包配置修改splitChunksPlugin配置
979
982
  if (splitChunksPlugin) {
980
983
  let needInit = false
package/lib/loader.js CHANGED
@@ -83,7 +83,7 @@ module.exports = function (content) {
83
83
  const loaderContext = this
84
84
  const isProduction = this.minimize || process.env.NODE_ENV === 'production'
85
85
  const filePath = this.resourcePath
86
- const moduleId = ctorType === 'app' ? MPX_APP_MODULE_ID : 'm' + mpx.pathHash(filePath)
86
+ const moduleId = ctorType === 'app' ? MPX_APP_MODULE_ID : '_' + mpx.pathHash(filePath)
87
87
 
88
88
  const parts = parseComponent(content, {
89
89
  filePath,
@@ -188,7 +188,7 @@ module.exports = function (content) {
188
188
  if (appName) this._module.addPresentationalDependency(new AppEntryDependency(resourcePath, appName))
189
189
  }
190
190
 
191
- const moduleId = ctorType === 'app' ? MPX_APP_MODULE_ID : 'm' + mpx.pathHash(filePath)
191
+ const moduleId = ctorType === 'app' ? MPX_APP_MODULE_ID : '_' + mpx.pathHash(filePath)
192
192
 
193
193
  if (ctorType !== 'app') {
194
194
  rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
@@ -252,7 +252,7 @@
252
252
  this.lastY = y
253
253
  }, 30, {
254
254
  leading: true,
255
- trailing: false
255
+ trailing: true
256
256
  }))
257
257
  this.bs.on('scrollEnd', () => {
258
258
  this.currentX = -this.bs.x
@@ -205,6 +205,7 @@
205
205
  momentum: false,
206
206
  bounce: false,
207
207
  probeType: 3,
208
+ bindToWrapper: true,
208
209
  stopPropagation: true
209
210
  }
210
211
  const bsOptions = Object.assign({}, originBsOptions, this.scrollOptions)
@@ -308,7 +308,9 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
308
308
  }
309
309
 
310
310
  if (App.onAppInit) {
311
+ global.__mpxAppInit = true
311
312
  Object.assign(option, App.onAppInit() || {})
313
+ global.__mpxAppInit = false
312
314
  }
313
315
 
314
316
  if (isBrowser && global.__mpxPinia) {
@@ -137,7 +137,7 @@ function stringifyDynamicClass (value) {
137
137
  }
138
138
 
139
139
  if (typeof value === 'string') {
140
- return mpEscape(value)
140
+ return value
141
141
  } else {
142
142
  return ''
143
143
  }
@@ -245,7 +245,7 @@ module.exports = {
245
245
  if (typeof staticClass !== 'string') {
246
246
  return console.log('Template attr class must be a string!')
247
247
  }
248
- return concat(staticClass, stringifyDynamicClass(dynamicClass))
248
+ return concat(staticClass, mpEscape(stringifyDynamicClass(dynamicClass)))
249
249
  },
250
250
  stringifyStyle: function (staticStyle, dynamicStyle) {
251
251
  var normalizedDynamicStyle = normalizeDynamicStyle(dynamicStyle)
@@ -1,7 +1,7 @@
1
1
  const path = require('path')
2
2
  const postcss = require('postcss')
3
3
  const loadPostcssConfig = require('./load-postcss-config')
4
- const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../utils/const')
4
+ const { MPX_ROOT_VIEW } = require('../utils/const')
5
5
  const rpx = require('./plugins/rpx')
6
6
  const vw = require('./plugins/vw')
7
7
  const pluginCondStrip = require('./plugins/conditional-strip')
@@ -15,7 +15,7 @@ module.exports = function (css, map) {
15
15
  const cb = this.async()
16
16
  const { resourcePath, queryObj } = parseRequest(this.resource)
17
17
  const mpx = this.getMpx()
18
- const id = queryObj.moduleId || queryObj.mid || 'm' + mpx.pathHash(resourcePath)
18
+ const id = queryObj.moduleId || queryObj.mid || '_' + mpx.pathHash(resourcePath)
19
19
  const appInfo = mpx.appInfo
20
20
  const defs = mpx.defs
21
21
  const mode = mpx.mode
@@ -90,7 +90,7 @@ module.exports = function (css, map) {
90
90
  .then(result => {
91
91
  // ali环境添加全局样式抹平root差异
92
92
  if ((mode === 'ali' || mode === 'web') && isApp) {
93
- result.css += `\n.${MPX_ROOT_VIEW} { display: initial }\n.${MPX_APP_MODULE_ID} { line-height: normal }`
93
+ result.css += `\n.${MPX_ROOT_VIEW} { display: initial }\npage { line-height: normal }`
94
94
  }
95
95
 
96
96
  for (const warning of result.warnings()) {
@@ -1878,9 +1878,11 @@ function getVirtualHostRoot (options, meta) {
1878
1878
  function processShow (el, options, root) {
1879
1879
  // 开启 virtualhost 全部走 props 传递处理
1880
1880
  // 未开启 virtualhost 直接绑定 display:none 到节点上
1881
- let show = getAndRemoveAttr(el, config[mode].directive.show).val
1881
+ let { val: show, has } = getAndRemoveAttr(el, config[mode].directive.show)
1882
1882
  if (mode === 'swan') show = wrapMustache(show)
1883
-
1883
+ if (has && show === undefined) {
1884
+ error$1(`Attrs ${config[mode].directive.show} should have a value `)
1885
+ }
1884
1886
  if (options.hasVirtualHost) {
1885
1887
  if (options.isComponent && el.parent === root && isRealNode(el)) {
1886
1888
  if (show !== undefined) {
@@ -1911,7 +1913,7 @@ function processShow (el, options, root) {
1911
1913
  oldStyle = oldStyle ? oldStyle + ';' : ''
1912
1914
  addAttrs(el, [{
1913
1915
  name: 'style',
1914
- value: `${oldStyle}{{${showExp}||${showExp}===undefined?'':'display:none;'}}`
1916
+ value: `${oldStyle}{{${showExp}?'':'display:none;'}}`
1915
1917
  }])
1916
1918
  }
1917
1919
  }
@@ -2182,7 +2184,7 @@ function postProcessComponentIs (el) {
2182
2184
  }
2183
2185
  let range = []
2184
2186
  if (el.attrsMap.range) {
2185
- range = getAndRemoveAttr(el, 'range').val.split(',')
2187
+ range = getAndRemoveAttr(el, 'range').val.split(',').map(item => item.trim())
2186
2188
  }
2187
2189
  el.components.forEach(function (component) {
2188
2190
  if (range.length > 0 && !range.includes(component)) return
@@ -27,7 +27,7 @@ module.exports = function (raw) {
27
27
  const hasComment = queryObj.hasComment
28
28
  const isNative = queryObj.isNative
29
29
  const hasScoped = queryObj.hasScoped
30
- const moduleId = queryObj.moduleId || 'm' + mpx.pathHash(resourcePath)
30
+ const moduleId = queryObj.moduleId || '_' + mpx.pathHash(resourcePath)
31
31
 
32
32
  let optimizeRenderLevel = 0
33
33
  for (const rule of optimizeRenderRules) {
@@ -2,6 +2,34 @@ const babylon = require('@babel/parser')
2
2
  const t = require('@babel/types')
3
3
  const traverse = require('@babel/traverse').default
4
4
  const generate = require('@babel/generator').default
5
+ const escapeReg = /[()[\]{}#!.:,%'"+$]/g
6
+ const escapeMap = {
7
+ '(': '_pl_',
8
+ ')': '_pr_',
9
+ '[': '_bl_',
10
+ ']': '_br_',
11
+ '{': '_cl_',
12
+ '}': '_cr_',
13
+ '#': '_h_',
14
+ '!': '_i_',
15
+ '/': '_s_',
16
+ '.': '_d_',
17
+ ':': '_c_',
18
+ ',': '_2c_',
19
+ '%': '_p_',
20
+ "'": '_q_',
21
+ '"': '_dq_',
22
+ '+': '_a_',
23
+ $: '_si_'
24
+ }
25
+
26
+ function mpEscape (str) {
27
+ return str.replace(escapeReg, function (match) {
28
+ if (escapeMap[match]) return escapeMap[match]
29
+ // unknown escaped
30
+ return '_u_'
31
+ })
32
+ }
5
33
 
6
34
  module.exports = function transDynamicClassExpr (expr, { error } = {}) {
7
35
  try {
@@ -14,13 +42,10 @@ module.exports = function transDynamicClassExpr (expr, { error } = {}) {
14
42
  ObjectExpression (path) {
15
43
  path.node.properties.forEach((property) => {
16
44
  if (t.isObjectProperty(property) && !property.computed) {
17
- const propertyName = property.key.name || property.key.value
45
+ let propertyName = property.key.name || property.key.value
46
+ propertyName = mpEscape(propertyName)
18
47
  if (/-/.test(propertyName)) {
19
- if (/\$/.test(propertyName)) {
20
- error && error(`Dynamic classname [${propertyName}] is not supported, which includes [-] char and [$] char at the same time.`)
21
- } else {
22
- property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
23
- }
48
+ property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
24
49
  } else {
25
50
  property.key = t.identifier(propertyName)
26
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.30",
3
+ "version": "2.9.32",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -82,5 +82,5 @@
82
82
  "engines": {
83
83
  "node": ">=14.14.0"
84
84
  },
85
- "gitHead": "5c1a417a5f474f071bd5b3ae43f668772c704ad3"
85
+ "gitHead": "61ac5a85a2b75304d8b989d4291b4f606f50d82f"
86
86
  }