@mpxjs/webpack-plugin 2.7.1-beta.4 → 2.7.1-beta.9

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.
@@ -29,7 +29,7 @@ class DynamicEntryDependency extends NullDependency {
29
29
  const publicPath = compilation.outputOptions.publicPath || ''
30
30
  let { resource, entryType, outputPath, relativePath, originEntryNode } = this
31
31
 
32
- const { packageRoot, outputPath: filename, alreadyOutputed } = mpx.getPackageInfo({
32
+ const { packageRoot, outputPath: filename, alreadyOutputted } = mpx.getPackageInfo({
33
33
  resource,
34
34
  outputPath,
35
35
  resourceType: entryType,
@@ -49,7 +49,7 @@ class DynamicEntryDependency extends NullDependency {
49
49
  // export类型的resultPath需要添加.js后缀
50
50
  if (entryType === 'export') resultPath += '.js'
51
51
 
52
- if (alreadyOutputed) return callback(null, { resultPath })
52
+ if (alreadyOutputted) return callback(null, { resultPath })
53
53
 
54
54
  if (packageRoot) {
55
55
  resource = addQuery(resource, { packageRoot })
@@ -16,10 +16,19 @@ class RecordResourceMapDependency extends NullDependency {
16
16
 
17
17
  mpxAction (module, compilation, callback) {
18
18
  const mpx = compilation.__mpx__
19
- const packageName = this.packageRoot || 'main'
20
- const resourceMap = mpx[`${this.resourceType}sMap`] || mpx.otherResourcesMap
21
- const subResourceMap = resourceMap.main ? resourceMap[packageName] : resourceMap
22
- subResourceMap[this.resourcePath] = this.outputPath
19
+ const { resourcePath, resourceType, outputPath, packageRoot } = this
20
+ mpx.recordResourceMap({
21
+ resourcePath,
22
+ resourceType,
23
+ outputPath,
24
+ packageRoot,
25
+ warn (e) {
26
+ compilation.warnings.push(e)
27
+ },
28
+ error (e) {
29
+ compilation.errors.push(e)
30
+ }
31
+ })
23
32
  return callback()
24
33
  }
25
34
 
package/lib/index.js CHANGED
@@ -219,6 +219,24 @@ class MpxWebpackPlugin {
219
219
  }
220
220
  }
221
221
 
222
+ static getPageEntry (request) {
223
+ return addQuery(request, { isPage: true })
224
+ }
225
+
226
+ static getComponentEntry (request) {
227
+ return addQuery(request, { isComponent: true })
228
+ }
229
+
230
+ static getPluginEntry (request) {
231
+ return addQuery(request, {
232
+ mpx: true,
233
+ extract: true,
234
+ isPlugin: true,
235
+ asScript: true,
236
+ type: 'json'
237
+ })
238
+ }
239
+
222
240
  runModeRules (data) {
223
241
  const { resourcePath, queryObj } = parseRequest(data.resource)
224
242
  if (queryObj.mode) {
@@ -488,7 +506,9 @@ class MpxWebpackPlugin {
488
506
  // 记录entryModule与entryNode的对应关系,用于体积分析
489
507
  entryNodeModulesMap: new Map(),
490
508
  // 记录与asset相关联的modules,用于体积分析
491
- assetModulesMap: new Map(),
509
+ assetsModulesMap: new Map(),
510
+ // 记录与asset相关联的ast,用于体积分析和esCheck,避免重复parse
511
+ assetsASTsMap: new Map(),
492
512
  usingComponents: {},
493
513
  // todo es6 map读写性能高于object,之后会逐步替换
494
514
  vueContentCache: new Map(),
@@ -577,15 +597,42 @@ class MpxWebpackPlugin {
577
597
  mpx.extractedFilesCache.set(resource, file)
578
598
  return file
579
599
  },
600
+ recordResourceMap: ({ resourcePath, resourceType, outputPath, packageRoot = '', warn, error }) => {
601
+ const packageName = packageRoot || 'main'
602
+ const resourceMap = mpx[`${resourceType}sMap`] || mpx.otherResourcesMap
603
+ const currentResourceMap = resourceMap.main ? resourceMap[packageName] = resourceMap[packageName] || {} : resourceMap
604
+ if (outputPath) {
605
+ if (!currentResourceMap[resourcePath] || currentResourceMap[resourcePath] === true) {
606
+ // 输出路径冲突检测,如果存在输出路径冲突,对输出路径进行重命名
607
+ // todo 用outputPathMap来检测输出路径冲突
608
+ for (let key in currentResourceMap) {
609
+ if (currentResourceMap[key] === outputPath && key !== resourcePath) {
610
+ outputPath = mpx.getOutputPath(resourcePath, resourceType, { conflictPath: outputPath })
611
+ warn && warn(new Error(`Current ${resourceType} [${resourcePath}] is registered with conflicted outputPath [${currentResourceMap[key]}] which is already existed in system, will be renamed with [${outputPath}], use ?resolve to get the real outputPath!`))
612
+ break
613
+ }
614
+ }
615
+ currentResourceMap[resourcePath] = outputPath
616
+ } else {
617
+ if (currentResourceMap[resourcePath] === outputPath) {
618
+ return true
619
+ } else {
620
+ error && error(new Error(`Current ${resourceType} [${resourcePath}] is already registered with outputPath [${currentResourceMap[resourcePath]}], you can not register it with another outputPath [${outputPath}]!`))
621
+ }
622
+ }
623
+ } else if (!currentResourceMap[resourcePath]) {
624
+ currentResourceMap[resourcePath] = true
625
+ }
626
+ return false
627
+ },
580
628
  // 组件和静态资源的输出规则如下:
581
629
  // 1. 主包引用的资源输出至主包
582
630
  // 2. 分包引用且主包引用过的资源输出至主包,不在当前分包重复输出
583
631
  // 3. 分包引用且无其他包引用的资源输出至当前分包
584
632
  // 4. 分包引用且其他分包也引用过的资源,重复输出至当前分包
585
- getPackageInfo: ({ resource, outputPath, resourceType, issuerResource, warn, error }) => {
633
+ getPackageInfo: ({ resource, resourceType, outputPath, issuerResource, warn, error }) => {
586
634
  let packageRoot = ''
587
635
  let packageName = 'main'
588
- let currentResourceMap = {}
589
636
 
590
637
  const { resourcePath } = parseRequest(resource)
591
638
  const currentPackageRoot = mpx.currentPackageRoot
@@ -594,7 +641,6 @@ class MpxWebpackPlugin {
594
641
  const resourceMap = mpx[`${resourceType}sMap`] || mpx.otherResourcesMap
595
642
 
596
643
  if (!resourceMap.main) {
597
- currentResourceMap = resourceMap
598
644
  packageRoot = currentPackageRoot
599
645
  packageName = currentPackageName
600
646
  } else {
@@ -625,36 +671,24 @@ class MpxWebpackPlugin {
625
671
  }
626
672
  }
627
673
  resourceMap[packageName] = resourceMap[packageName] || {}
628
- currentResourceMap = resourceMap[packageName]
629
674
  }
630
675
 
631
- let alreadyOutputed = false
632
- if (outputPath) {
633
- outputPath = toPosix(path.join(packageRoot, outputPath))
634
- // 如果之前已经进行过输出,则不需要重复进行
635
- if (currentResourceMap[resourcePath] === outputPath) {
636
- alreadyOutputed = true
637
- } else {
638
- // todo 用outputPathMap来检测冲突
639
- // 输出冲突检测,如果存在输出路径冲突,对输出路径进行重命名
640
- for (let key in currentResourceMap) {
641
- if (currentResourceMap[key] === outputPath && key !== resourcePath) {
642
- outputPath = toPosix(path.join(packageRoot, mpx.getOutputPath(resourcePath, resourceType, { conflictPath: outputPath })))
643
- warn && warn(new Error(`Current ${resourceType} [${resourcePath}] is registered with a conflict outputPath [${currentResourceMap[key]}] which is already existed in system, will be renamed with [${outputPath}], use ?resolve to get the real outputPath!`))
644
- break
645
- }
646
- }
647
- currentResourceMap[resourcePath] = outputPath
648
- }
649
- } else if (!currentResourceMap[resourcePath]) {
650
- currentResourceMap[resourcePath] = true
651
- }
676
+ if (outputPath) outputPath = toPosix(path.join(packageRoot, outputPath))
677
+
678
+ const alreadyOutputted = mpx.recordResourceMap({
679
+ resourcePath,
680
+ resourceType,
681
+ outputPath,
682
+ packageRoot,
683
+ warn,
684
+ error
685
+ })
652
686
 
653
687
  return {
654
688
  packageName,
655
689
  packageRoot,
656
690
  outputPath,
657
- alreadyOutputed
691
+ alreadyOutputted
658
692
  }
659
693
  }
660
694
  }
@@ -793,9 +827,9 @@ class MpxWebpackPlugin {
793
827
  })
794
828
 
795
829
  compilation.hooks.moduleAsset.tap('MpxWebpackPlugin', (module, filename) => {
796
- const modules = mpx.assetModulesMap.get(filename) || new Set()
830
+ const modules = mpx.assetsModulesMap.get(filename) || new Set()
797
831
  modules.add(module)
798
- mpx.assetModulesMap.set(filename, modules)
832
+ mpx.assetsModulesMap.set(filename, modules)
799
833
  })
800
834
 
801
835
  compilation.hooks.beforeModuleAssets.tap('MpxWebpackPlugin', () => {
package/lib/loader.js CHANGED
@@ -51,7 +51,7 @@ module.exports = function (content) {
51
51
  }
52
52
 
53
53
  // 支持资源query传入isPage或isComponent支持页面/组件单独编译
54
- if (queryObj.isComponent || queryObj.isPage) {
54
+ if (ctorType === 'app' && (queryObj.isComponent || queryObj.isPage)) {
55
55
  const entryName = getEntryName(this) || (queryObj.isComponent ? 'noEntryComponent' : 'noEntryPage')
56
56
  ctorType = queryObj.isComponent ? 'component' : 'page'
57
57
  this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, ctorType, entryName, packageRoot))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.7.1-beta.4",
3
+ "version": "2.7.1-beta.9",
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": "bb23a30c136854abc94e9b31a36b0857a00e45d4"
83
+ "gitHead": "1db86dfb15540cb9e65acf8066e517bf48be29fd"
84
84
  }