@mpxjs/webpack-plugin 2.7.20 → 2.7.24
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
|
@@ -22,6 +22,7 @@ const ExternalsPlugin = require('webpack/lib/ExternalsPlugin')
|
|
|
22
22
|
const AddModePlugin = require('./resolver/AddModePlugin')
|
|
23
23
|
const AddEnvPlugin = require('./resolver/AddEnvPlugin')
|
|
24
24
|
const PackageEntryPlugin = require('./resolver/PackageEntryPlugin')
|
|
25
|
+
const FixDescriptionInfoPlugin = require('./resolver/FixDescriptionInfoPlugin')
|
|
25
26
|
// const CommonJsRequireDependency = require('webpack/lib/dependencies/CommonJsRequireDependency')
|
|
26
27
|
// const HarmonyImportSideEffectDependency = require('webpack/lib/dependencies/HarmonyImportSideEffectDependency')
|
|
27
28
|
// const RequireHeaderDependency = require('webpack/lib/dependencies/RequireHeaderDependency')
|
|
@@ -302,6 +303,7 @@ class MpxWebpackPlugin {
|
|
|
302
303
|
compiler.options.resolve.plugins.push(addEnvPlugin)
|
|
303
304
|
}
|
|
304
305
|
compiler.options.resolve.plugins.push(packageEntryPlugin)
|
|
306
|
+
compiler.options.resolve.plugins.push(new FixDescriptionInfoPlugin())
|
|
305
307
|
|
|
306
308
|
let splitChunksPlugin
|
|
307
309
|
let splitChunksOptions
|
|
@@ -789,14 +791,25 @@ class MpxWebpackPlugin {
|
|
|
789
791
|
}
|
|
790
792
|
}
|
|
791
793
|
} else if (independent) {
|
|
792
|
-
// ContextModule/RawModule
|
|
793
|
-
const
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
794
|
+
// ContextModule/RawModule/ExternalModule等只在独立分包的情况下添加分包标记,其余默认不添加
|
|
795
|
+
const hackModuleIdentifier = (module) => {
|
|
796
|
+
const postfix = `|independent=${independent}|${currentPackageRoot}`
|
|
797
|
+
const rawIdentifier = module.identifier
|
|
798
|
+
if (rawIdentifier && !rawIdentifier.__mpxHacked) {
|
|
799
|
+
module.identifier = () => {
|
|
800
|
+
return rawIdentifier.call(module) + postfix
|
|
801
|
+
}
|
|
802
|
+
module.identifier.__mpxHacked = true
|
|
798
803
|
}
|
|
799
804
|
}
|
|
805
|
+
hackModuleIdentifier(module)
|
|
806
|
+
const rawCallback = callback
|
|
807
|
+
callback = (err, module) => {
|
|
808
|
+
// 因为文件缓存的存在,前面hack identifier的行为对于从文件缓存中创建得到的module并不生效,因此需要在回调中进行二次hack处理
|
|
809
|
+
if (err) return rawCallback(err)
|
|
810
|
+
hackModuleIdentifier(module)
|
|
811
|
+
rawCallback(null, module)
|
|
812
|
+
}
|
|
800
813
|
}
|
|
801
814
|
return rawAddModule.call(compilation, module, callback)
|
|
802
815
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
|
|
3
|
+
module.exports = class FixDescriptionInfoPlugin {
|
|
4
|
+
apply (resolver) {
|
|
5
|
+
resolver.hooks.result.tap('FixDescriptionInfoPlugin', (request) => {
|
|
6
|
+
const { path: resourcePath } = request
|
|
7
|
+
const segments = resourcePath.split(path.sep)
|
|
8
|
+
let rootIndex = -1
|
|
9
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
10
|
+
const segment = segments[i]
|
|
11
|
+
if (segment === 'node_modules') {
|
|
12
|
+
rootIndex = segments[i + 1].startsWith('@') ? i + 2 : i + 1
|
|
13
|
+
break
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (rootIndex !== -1) {
|
|
17
|
+
const descriptionFileRoot = segments.slice(0, rootIndex + 1).join(path.sep)
|
|
18
|
+
const descriptionFilePath = path.join(descriptionFileRoot, 'package.json')
|
|
19
|
+
if (descriptionFilePath !== request.descriptionFilePath) {
|
|
20
|
+
Object.assign(request, {
|
|
21
|
+
descriptionFileRoot,
|
|
22
|
+
descriptionFilePath
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -16,7 +16,7 @@ module.exports = class PackageEntryPlugin {
|
|
|
16
16
|
*/
|
|
17
17
|
apply (resolver) {
|
|
18
18
|
const target = resolver.ensureHook(this.target)
|
|
19
|
-
resolver.getHook(this.source).tapAsync('
|
|
19
|
+
resolver.getHook(this.source).tapAsync('PackageEntryPlugin', (request, resolveContext, callback) => {
|
|
20
20
|
if (request.miniprogram) return callback()
|
|
21
21
|
let { path: resourcePath, descriptionFileData, descriptionFileRoot } = request
|
|
22
22
|
if (request.miniprogram || !descriptionFileData) return callback()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.24",
|
|
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": "
|
|
83
|
+
"gitHead": "1764785d4da33a7ea9004edc7ea18596262c7969"
|
|
84
84
|
}
|