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

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
@@ -577,15 +577,42 @@ class MpxWebpackPlugin {
577
577
  mpx.extractedFilesCache.set(resource, file)
578
578
  return file
579
579
  },
580
+ recordResourceMap: ({ resourcePath, resourceType, outputPath, packageRoot = '', warn, error }) => {
581
+ const packageName = packageRoot || 'main'
582
+ const resourceMap = mpx[`${resourceType}sMap`] || mpx.otherResourcesMap
583
+ const currentResourceMap = resourceMap.main ? resourceMap[packageName] = resourceMap[packageName] || {} : resourceMap
584
+ if (outputPath) {
585
+ if (!currentResourceMap[resourcePath] || currentResourceMap[resourcePath] === true) {
586
+ // 输出路径冲突检测,如果存在输出路径冲突,对输出路径进行重命名
587
+ // todo 用outputPathMap来检测输出路径冲突
588
+ for (let key in currentResourceMap) {
589
+ if (currentResourceMap[key] === outputPath && key !== resourcePath) {
590
+ outputPath = mpx.getOutputPath(resourcePath, resourceType, { conflictPath: outputPath })
591
+ 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!`))
592
+ break
593
+ }
594
+ }
595
+ currentResourceMap[resourcePath] = outputPath
596
+ } else {
597
+ if (currentResourceMap[resourcePath] === outputPath) {
598
+ return true
599
+ } else {
600
+ error && error(new Error(`Current ${resourceType} [${resourcePath}] is already registered with outputPath [${currentResourceMap[resourcePath]}], you can not register it with another outputPath [${outputPath}]!`))
601
+ }
602
+ }
603
+ } else if (!currentResourceMap[resourcePath]) {
604
+ currentResourceMap[resourcePath] = true
605
+ }
606
+ return false
607
+ },
580
608
  // 组件和静态资源的输出规则如下:
581
609
  // 1. 主包引用的资源输出至主包
582
610
  // 2. 分包引用且主包引用过的资源输出至主包,不在当前分包重复输出
583
611
  // 3. 分包引用且无其他包引用的资源输出至当前分包
584
612
  // 4. 分包引用且其他分包也引用过的资源,重复输出至当前分包
585
- getPackageInfo: ({ resource, outputPath, resourceType, issuerResource, warn, error }) => {
613
+ getPackageInfo: ({ resource, resourceType, outputPath, issuerResource, warn, error }) => {
586
614
  let packageRoot = ''
587
615
  let packageName = 'main'
588
- let currentResourceMap = {}
589
616
 
590
617
  const { resourcePath } = parseRequest(resource)
591
618
  const currentPackageRoot = mpx.currentPackageRoot
@@ -594,7 +621,6 @@ class MpxWebpackPlugin {
594
621
  const resourceMap = mpx[`${resourceType}sMap`] || mpx.otherResourcesMap
595
622
 
596
623
  if (!resourceMap.main) {
597
- currentResourceMap = resourceMap
598
624
  packageRoot = currentPackageRoot
599
625
  packageName = currentPackageName
600
626
  } else {
@@ -625,36 +651,24 @@ class MpxWebpackPlugin {
625
651
  }
626
652
  }
627
653
  resourceMap[packageName] = resourceMap[packageName] || {}
628
- currentResourceMap = resourceMap[packageName]
629
654
  }
630
655
 
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
- }
656
+ if (outputPath) outputPath = toPosix(path.join(packageRoot, outputPath))
657
+
658
+ const alreadyOutputted = mpx.recordResourceMap({
659
+ resourcePath,
660
+ resourceType,
661
+ outputPath,
662
+ packageRoot,
663
+ warn,
664
+ error
665
+ })
652
666
 
653
667
  return {
654
668
  packageName,
655
669
  packageRoot,
656
670
  outputPath,
657
- alreadyOutputed
671
+ alreadyOutputted
658
672
  }
659
673
  }
660
674
  }
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.5",
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": "0fd6f58e2e6e343c1a90104d0e796e3528b2c1a3"
84
84
  }