webpack-federation-stats-plugin 1.0.2 → 1.1.0
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/FederationStatsPlugin.js +85 -80
- package/LICENSE +21 -21
- package/README.md +40 -40
- package/index.d.ts +12 -0
- package/package.json +28 -22
package/FederationStatsPlugin.js
CHANGED
|
@@ -1,80 +1,85 @@
|
|
|
1
|
-
const PLUGIN_NAME = "FederationStatsPlugin"
|
|
2
|
-
|
|
3
|
-
const EXTENSION_REGEX = /\.[^/.]+$/
|
|
4
|
-
|
|
5
|
-
class FederationStatsPlugin {
|
|
6
|
-
constructor(options = {
|
|
7
|
-
this._options = options
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
apply(compiler) {
|
|
11
|
-
const federationPlugin = compiler.options.plugins && compiler.options.plugins.find((plugin) => plugin.constructor.name === "ModuleFederationPlugin")
|
|
12
|
-
|
|
13
|
-
if (!federationPlugin) throw new Error("No ModuleFederationPlugin found.")
|
|
14
|
-
|
|
15
|
-
const appName = federationPlugin._options.name
|
|
16
|
-
|
|
17
|
-
// get exposed modules from the ModuleFederationPlugin
|
|
18
|
-
const exposedFiles = new Map(Object.entries(federationPlugin._options.exposes || {}).map(([k, v]) => (typeof v === "object" ? [v.import, k] : [v, k])))
|
|
19
|
-
|
|
20
|
-
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
21
|
-
compilation.hooks.processAssets.tapPromise(
|
|
22
|
-
{
|
|
23
|
-
name: PLUGIN_NAME,
|
|
24
|
-
stage: compilation.constructor.PROCESS_ASSETS_STAGE_REPORT,
|
|
25
|
-
},
|
|
26
|
-
async () => {
|
|
27
|
-
const stats = compilation.getStats().toJson({})
|
|
28
|
-
// find mf modules
|
|
29
|
-
const mfModules = stats.modules.filter((module) => module.issuerName === "container entry" && exposedFiles.has(module.name.replace(EXTENSION_REGEX, "")))
|
|
30
|
-
|
|
31
|
-
const chunksReducer = (chunksArr, current) => {
|
|
32
|
-
current.siblings.forEach((s) => {
|
|
33
|
-
const chunk = stats.chunks.find((c) => c.id === s)
|
|
34
|
-
chunk.files.forEach((f) => chunksArr.push(f))
|
|
35
|
-
})
|
|
36
|
-
current.files.forEach((f) => chunksArr.push(f))
|
|
37
|
-
return chunksArr
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const chunks = mfModules.map((module) => {
|
|
41
|
-
const exposedAs = exposedFiles.get(module.name.replace(EXTENSION_REGEX, ""))
|
|
42
|
-
const chunks = module.chunks
|
|
43
|
-
.map((chunkId) => stats.chunks.find((chunk) => chunk.id === chunkId))
|
|
44
|
-
.filter((chunk) => chunk.runtime.includes(appName))
|
|
45
|
-
.reduce(chunksReducer, [])
|
|
46
|
-
return {
|
|
47
|
-
module: exposedAs,
|
|
48
|
-
chunks: chunks,
|
|
49
|
-
id: module.id,
|
|
50
|
-
}
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
const exposes = chunks.reduce((result, current) => Object.assign(result, {[current.module.replace("./", "")]: current.chunks}), {})
|
|
54
|
-
const name = (federationPlugin._options.library && federationPlugin._options.library.name) || federationPlugin._options.name
|
|
55
|
-
|
|
56
|
-
const statsResult = {
|
|
57
|
-
name,
|
|
58
|
-
exposes,
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
1
|
+
const PLUGIN_NAME = "FederationStatsPlugin"
|
|
2
|
+
|
|
3
|
+
const EXTENSION_REGEX = /\.[^/.]+$/
|
|
4
|
+
|
|
5
|
+
class FederationStatsPlugin {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
this._options = {fileName: "federation-stats.json", ...options}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
apply(compiler) {
|
|
11
|
+
const federationPlugin = compiler.options.plugins && compiler.options.plugins.find((plugin) => plugin.constructor.name === "ModuleFederationPlugin")
|
|
12
|
+
|
|
13
|
+
if (!federationPlugin) throw new Error("No ModuleFederationPlugin found.")
|
|
14
|
+
|
|
15
|
+
const appName = federationPlugin._options.name
|
|
16
|
+
|
|
17
|
+
// get exposed modules from the ModuleFederationPlugin
|
|
18
|
+
const exposedFiles = new Map(Object.entries(federationPlugin._options.exposes || {}).map(([k, v]) => (typeof v === "object" ? [v.import, k] : [v, k])))
|
|
19
|
+
|
|
20
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
21
|
+
compilation.hooks.processAssets.tapPromise(
|
|
22
|
+
{
|
|
23
|
+
name: PLUGIN_NAME,
|
|
24
|
+
stage: compilation.constructor.PROCESS_ASSETS_STAGE_REPORT,
|
|
25
|
+
},
|
|
26
|
+
async () => {
|
|
27
|
+
const stats = compilation.getStats().toJson({})
|
|
28
|
+
// find mf modules
|
|
29
|
+
const mfModules = stats.modules.filter((module) => module.issuerName === "container entry" && exposedFiles.has(module.name.replace(EXTENSION_REGEX, "")))
|
|
30
|
+
|
|
31
|
+
const chunksReducer = (chunksArr, current) => {
|
|
32
|
+
current.siblings.forEach((s) => {
|
|
33
|
+
const chunk = stats.chunks.find((c) => c.id === s)
|
|
34
|
+
chunk.files.forEach((f) => chunksArr.push(f))
|
|
35
|
+
})
|
|
36
|
+
current.files.forEach((f) => chunksArr.push(f))
|
|
37
|
+
return chunksArr
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const chunks = mfModules.map((module) => {
|
|
41
|
+
const exposedAs = exposedFiles.get(module.name.replace(EXTENSION_REGEX, ""))
|
|
42
|
+
const chunks = module.chunks
|
|
43
|
+
.map((chunkId) => stats.chunks.find((chunk) => chunk.id === chunkId))
|
|
44
|
+
.filter((chunk) => chunk.runtime.includes(appName))
|
|
45
|
+
.reduce(chunksReducer, [])
|
|
46
|
+
return {
|
|
47
|
+
module: exposedAs,
|
|
48
|
+
chunks: chunks,
|
|
49
|
+
id: module.id,
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const exposes = chunks.reduce((result, current) => Object.assign(result, {[current.module.replace("./", "")]: current.chunks}), {})
|
|
54
|
+
const name = (federationPlugin._options.library && federationPlugin._options.library.name) || federationPlugin._options.name
|
|
55
|
+
|
|
56
|
+
const statsResult = {
|
|
57
|
+
name,
|
|
58
|
+
exposes,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const publicUrl = this._options.publicUrl
|
|
62
|
+
if (publicUrl) {
|
|
63
|
+
statsResult.publicUrl = publicUrl
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const fileName = this._options.fileName
|
|
67
|
+
const statsBuffer = Buffer.from(JSON.stringify(statsResult), "utf-8")
|
|
68
|
+
const mfStats = {
|
|
69
|
+
source: () => statsBuffer,
|
|
70
|
+
size: () => statsBuffer.length,
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const asset = compilation.getAsset(fileName)
|
|
74
|
+
if (asset) {
|
|
75
|
+
compilation.updateAsset(fileName, mfStats)
|
|
76
|
+
} else {
|
|
77
|
+
compilation.emitAsset(fileName, mfStats)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
module.exports = FederationStatsPlugin
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 DanielAmenou
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 DanielAmenou
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
# webpack-federation-stats-plugin
|
|
2
|
-
|
|
3
|
-
## Installation
|
|
4
|
-
|
|
5
|
-
`npm i --save-dev webpack-federation-stats-plugin`
|
|
6
|
-
|
|
7
|
-
`yarn add --dev webpack-federation-stats-plugin`
|
|
8
|
-
|
|
9
|
-
## Usage
|
|
10
|
-
|
|
11
|
-
```javascript
|
|
12
|
-
const FederationStatsPlugin = require("webpack-federation-stats-plugin");
|
|
13
|
-
|
|
14
|
-
module.exports = {
|
|
15
|
-
plugins: [
|
|
16
|
-
new FederationStatsPlugin({filename: "federation-stats.json"}),
|
|
17
|
-
],
|
|
18
|
-
};
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### Example Output
|
|
22
|
-
|
|
23
|
-
```json
|
|
24
|
-
{
|
|
25
|
-
"name": "AppName",
|
|
26
|
-
"exposes": {
|
|
27
|
-
"module1": [
|
|
28
|
-
"vendors-node_modules_babel_runtime_helpers_esm_slicedToArray.js",
|
|
29
|
-
"vendors-node_modules_core-js.js",
|
|
30
|
-
"vendors-node_modules_prop-types_index_js.js",
|
|
31
|
-
],
|
|
32
|
-
"module2": ["vendors-node_modules_core-js.js",],
|
|
33
|
-
"module3": [
|
|
34
|
-
"vendors-node_modules_babel.js",
|
|
35
|
-
"vendors-node_modules_core-js.js",
|
|
36
|
-
]
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
```
|
|
1
|
+
# webpack-federation-stats-plugin
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
`npm i --save-dev webpack-federation-stats-plugin`
|
|
6
|
+
|
|
7
|
+
`yarn add --dev webpack-federation-stats-plugin`
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
const FederationStatsPlugin = require("webpack-federation-stats-plugin");
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
plugins: [
|
|
16
|
+
new FederationStatsPlugin({filename: "federation-stats.json"}),
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Example Output
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"name": "AppName",
|
|
26
|
+
"exposes": {
|
|
27
|
+
"module1": [
|
|
28
|
+
"vendors-node_modules_babel_runtime_helpers_esm_slicedToArray.js",
|
|
29
|
+
"vendors-node_modules_core-js.js",
|
|
30
|
+
"vendors-node_modules_prop-types_index_js.js",
|
|
31
|
+
],
|
|
32
|
+
"module2": ["vendors-node_modules_core-js.js",],
|
|
33
|
+
"module3": [
|
|
34
|
+
"vendors-node_modules_babel.js",
|
|
35
|
+
"vendors-node_modules_core-js.js",
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
```
|
package/index.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "webpack-federation-stats-plugin",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "webpack-federation-stats-plugin",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"types": "index.d.ts",
|
|
5
|
+
"description": "export module federation stats",
|
|
6
|
+
"main": "FederationStatsPlugin.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"publish:beta": "npm version prerelease --preid=beta -m \"beta version - %s\" && npm publish --tag beta",
|
|
10
|
+
"publish:patch": "npm version patch -m \"patch version - %s\" && npm publish",
|
|
11
|
+
"publish:minor": "npm version minor -m \"minor version - %s\" && npm publish",
|
|
12
|
+
"publish:major": "npm version major -m \"major version - %s\" && npm publish",
|
|
13
|
+
"postpublish": "git push && git push --tags"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/DanielAmenou/webpack-federation-stats-plugin#readme",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/DanielAmenou/webpack-federation-stats-plugin.git"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"webpack",
|
|
22
|
+
"plugin",
|
|
23
|
+
"module federation",
|
|
24
|
+
"loadable-components"
|
|
25
|
+
],
|
|
26
|
+
"author": "Daniel Amenou <amenou.daniel@gmail.com>",
|
|
27
|
+
"license": "MIT"
|
|
28
|
+
}
|