@mpxjs/webpack-plugin 2.8.46 → 2.8.48

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
@@ -170,6 +170,7 @@ class MpxWebpackPlugin {
170
170
  options.asyncSubpackageRules = options.asyncSubpackageRules || null
171
171
  options.retryRequireAsync = options.retryRequireAsync || false
172
172
  options.enableAliRequireAsync = options.enableAliRequireAsync || false
173
+ options.optimizeSize = options.optimizeSize || false
173
174
  this.options = options
174
175
  // Hack for buildDependencies
175
176
  const rawResolveBuildDependencies = FileSystemInfo.prototype.resolveBuildDependencies
@@ -294,6 +295,14 @@ class MpxWebpackPlugin {
294
295
  warnings.push(`webpack options: MpxWebpackPlugin accept options.output.filename to be ${outputFilename} only, custom options.output.filename will be ignored!`)
295
296
  }
296
297
  compiler.options.output.filename = compiler.options.output.chunkFilename = outputFilename
298
+ if (this.options.optimizeSize) {
299
+ compiler.options.optimization.chunkIds = 'total-size'
300
+ compiler.options.optimization.moduleIds = 'natural'
301
+ compiler.options.optimization.mangleExports = 'size'
302
+ compiler.options.output.globalObject = 'g'
303
+ // todo chunkLoadingGlobal不具备项目唯一性,在多构建产物混编时可能存在问题,尤其在支付宝使用全局对象传递的情况下
304
+ compiler.options.output.chunkLoadingGlobal = 'c'
305
+ }
297
306
  }
298
307
 
299
308
  if (!compiler.options.node || !compiler.options.node.global) {
@@ -387,6 +396,7 @@ class MpxWebpackPlugin {
387
396
  const query = parseQuery(obj.query || '?')
388
397
  return query.isPage && !query.type
389
398
  }
399
+
390
400
  // new PartialCompilePlugin(this.options.partialCompile).apply(compiler)
391
401
  compiler.resolverFactory.hooks.resolver.intercept({
392
402
  factory: (type, hook) => {
@@ -685,7 +695,15 @@ class MpxWebpackPlugin {
685
695
  mpx.extractedFilesCache.set(resource, file)
686
696
  return file
687
697
  },
688
- recordResourceMap: ({ resourcePath, resourceType, outputPath, packageRoot = '', recordOnly, warn, error }) => {
698
+ recordResourceMap: ({
699
+ resourcePath,
700
+ resourceType,
701
+ outputPath,
702
+ packageRoot = '',
703
+ recordOnly,
704
+ warn,
705
+ error
706
+ }) => {
689
707
  const packageName = packageRoot || 'main'
690
708
  const resourceMap = mpx[`${resourceType}sMap`] || mpx.otherResourcesMap
691
709
  const currentResourceMap = resourceMap.main ? resourceMap[packageName] = resourceMap[packageName] || {} : resourceMap
@@ -1297,6 +1315,8 @@ class MpxWebpackPlugin {
1297
1315
  chunkLoadingGlobal
1298
1316
  } = compilation.outputOptions
1299
1317
 
1318
+ const chunkLoadingGlobalStr = JSON.stringify(chunkLoadingGlobal)
1319
+
1300
1320
  function getTargetFile (file) {
1301
1321
  let targetFile = file
1302
1322
  const queryStringIdx = targetFile.indexOf('?')
@@ -1316,7 +1336,7 @@ class MpxWebpackPlugin {
1316
1336
 
1317
1337
  const originalSource = compilation.assets[chunkFile]
1318
1338
  const source = new ConcatSource()
1319
- source.add(`\nvar ${globalObject} = ${globalObject} || {};\n\n`)
1339
+ source.add(`\nvar ${globalObject} = {};\n`)
1320
1340
 
1321
1341
  relativeChunks.forEach((relativeChunk, index) => {
1322
1342
  const relativeChunkFile = relativeChunk.files.values().next().value
@@ -1333,16 +1353,16 @@ class MpxWebpackPlugin {
1333
1353
  if (compilation.options.entry[chunk.name]) {
1334
1354
  // 在rootChunk中挂载jsonpCallback
1335
1355
  source.add('// process ali subpackages runtime in root chunk\n' +
1336
- 'var context = (function() { return this })() || Function("return this")();\n\n')
1337
- source.add(`context[${JSON.stringify(chunkLoadingGlobal)}] = ${globalObject}[${JSON.stringify(chunkLoadingGlobal)}] = require("${relativePath}");\n`)
1356
+ 'var context = (function() { return this })() || Function("return this")();\n')
1357
+ source.add(`context[${chunkLoadingGlobalStr}] = ${globalObject}[${chunkLoadingGlobalStr}] = require("${relativePath}");\n`)
1338
1358
  } else {
1339
1359
  // 其余chunk中通过context全局传递runtime
1340
1360
  source.add('// process ali subpackages runtime in other chunk\n' +
1341
- 'var context = (function() { return this })() || Function("return this")();\n\n')
1342
- source.add(`${globalObject}[${JSON.stringify(chunkLoadingGlobal)}] = context[${JSON.stringify(chunkLoadingGlobal)}];\n`)
1361
+ 'var context = (function() { return this })() || Function("return this")();\n')
1362
+ source.add(`${globalObject}[${chunkLoadingGlobalStr}] = context[${chunkLoadingGlobalStr}];\n`)
1343
1363
  }
1344
1364
  } else {
1345
- source.add(`${globalObject}[${JSON.stringify(chunkLoadingGlobal)}] = require("${relativePath}");\n`)
1365
+ source.add(`${globalObject}[${chunkLoadingGlobalStr}] = require("${relativePath}");\n`)
1346
1366
  }
1347
1367
  } else {
1348
1368
  source.add(`require("${relativePath}");\n`)
@@ -1350,10 +1370,11 @@ class MpxWebpackPlugin {
1350
1370
  })
1351
1371
 
1352
1372
  if (isRuntime) {
1353
- source.add('var context = (function() { return this })() || Function("return this")();\n')
1354
- source.add(`
1373
+ if (mpx.mode === 'ali' || mpx.mode === 'qq') {
1374
+ source.add(`
1355
1375
  // Fix babel runtime in some quirky environment like ali & qq dev.
1356
1376
  try {
1377
+ var context = (function() { return this })() || Function("return this")();
1357
1378
  if(!context.console){
1358
1379
  context.console = console;
1359
1380
  context.setInterval = setInterval;
@@ -1394,8 +1415,9 @@ try {
1394
1415
  }
1395
1416
  } catch(e){
1396
1417
  }\n`)
1418
+ }
1397
1419
  source.add(originalSource)
1398
- source.add(`\nmodule.exports = ${globalObject}[${JSON.stringify(chunkLoadingGlobal)}];\n`)
1420
+ source.add(`\nmodule.exports = ${globalObject}[${chunkLoadingGlobalStr}];\n`)
1399
1421
  } else {
1400
1422
  source.add(originalSource)
1401
1423
  }
@@ -193,14 +193,7 @@ module.exports = function getSpec ({ warn, error }) {
193
193
  // 不过滤的话每一个属性都要 parse
194
194
  el.attrsList.filter(item => this.test.test(item.name)).forEach((item) => {
195
195
  const parsed = parseMustache(item.value)
196
- if (item.name === 'wx:style') {
197
- styleBinding.push(parsed.result)
198
- // item.name === 'style'
199
- } else if (parsed.hasBinding || parsed.result.indexOf('rpx') > -1) {
200
- styleBinding.push(parsed.result)
201
- } else {
202
- styleBinding.push(JSON.stringify(item.value))
203
- }
196
+ styleBinding.push(parsed.result)
204
197
  })
205
198
  return {
206
199
  name: ':style',
@@ -878,6 +878,7 @@ function moveBaseDirective (target, from, isDelete = true) {
878
878
  }
879
879
 
880
880
  function stringify (str) {
881
+ if (mode === 'web') str = str.replace(/'/g, '"')
881
882
  return JSON.stringify(str)
882
883
  }
883
884
 
@@ -988,7 +989,7 @@ function parseFuncStr2 (str) {
988
989
  if (subIndex) {
989
990
  const index1 = ret.index + subIndex
990
991
  const index2 = index1 + 6
991
- args = args.substring(0, index1) + JSON.stringify(eventIdentifier) + args.substring(index2)
992
+ args = args.substring(0, index1) + stringify(eventIdentifier) + args.substring(index2)
992
993
  }
993
994
  }
994
995
  return {
@@ -1016,7 +1017,7 @@ function stringifyWithResolveComputed (modelValue) {
1016
1017
  computedStack.push(char)
1017
1018
  if (computedStack.length === 1) {
1018
1019
  fragment += '.'
1019
- result.push(JSON.stringify(fragment))
1020
+ result.push(stringify(fragment))
1020
1021
  fragment = ''
1021
1022
  continue
1022
1023
  }
@@ -1033,7 +1034,7 @@ function stringifyWithResolveComputed (modelValue) {
1033
1034
  fragment += char
1034
1035
  }
1035
1036
  if (fragment !== '') {
1036
- result.push(JSON.stringify(fragment))
1037
+ result.push(stringify(fragment))
1037
1038
  }
1038
1039
  return result.join('+')
1039
1040
  }
@@ -1696,7 +1697,7 @@ function processWebExternalClassesHack (el, options) {
1696
1697
  options.externalClasses.forEach((className) => {
1697
1698
  const index = classNames.indexOf(className)
1698
1699
  if (index > -1) {
1699
- replacements.push(`$attrs[${JSON.stringify(className)}]`)
1700
+ replacements.push(`$attrs[${stringify(className)}]`)
1700
1701
  classNames.splice(index, 1)
1701
1702
  }
1702
1703
  })
@@ -1730,13 +1731,13 @@ function processWebExternalClassesHack (el, options) {
1730
1731
  options.externalClasses.forEach((className) => {
1731
1732
  const index = classNames.indexOf(className)
1732
1733
  if (index > -1) {
1733
- replacements.push(`$attrs[${JSON.stringify(className)}]`)
1734
+ replacements.push(`$attrs[${stringify(className)}]`)
1734
1735
  classNames.splice(index, 1)
1735
1736
  }
1736
1737
  })
1737
1738
 
1738
1739
  if (classNames.length) {
1739
- replacements.unshift(JSON.stringify(classNames.join(' ')))
1740
+ replacements.unshift(stringify(classNames.join(' ')))
1740
1741
  }
1741
1742
 
1742
1743
  addAttrs(el, [{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.46",
3
+ "version": "2.8.48",
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": "dcf6f000660d56207ff414cb776e8bc6d5ce651f"
85
+ "gitHead": "4cbd364322aadc0e9727a0d852ca3ca1c8e0b1ca"
86
86
  }