rollup-plugin-webpack-stats 0.0.1 → 0.0.2
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/README.md +5 -2
- package/dist/rollup-plugin-webpack-stats.cjs.development.js +10 -6
- package/dist/rollup-plugin-webpack-stats.cjs.development.js.map +1 -1
- package/dist/rollup-plugin-webpack-stats.cjs.production.min.js +1 -1
- package/dist/rollup-plugin-webpack-stats.cjs.production.min.js.map +1 -1
- package/dist/rollup-plugin-webpack-stats.esm.js +10 -6
- package/dist/rollup-plugin-webpack-stats.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/transform.ts +14 -4
package/README.md
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
# rollup-plugin-webpack-stats
|
|
2
2
|
|
|
3
|
-
>
|
|
4
|
-
|
|
3
|
+
> **Warning**
|
|
4
|
+
Under active development
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/rollup-plugin-webpack-stats)
|
|
7
|
+

|
|
5
8
|
|
|
6
9
|
Generate rollup stats JSON file with a [bundle-stats](https://github.com/relative-ci/bundle-stats/tree/master/packages/cli) webpack [supported sructure](https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts).
|
|
7
10
|
|
|
@@ -6,6 +6,12 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
6
6
|
|
|
7
7
|
var path = _interopDefault(require('node:path'));
|
|
8
8
|
|
|
9
|
+
var getByteSize = function getByteSize(content) {
|
|
10
|
+
if (typeof content === 'string') {
|
|
11
|
+
return Buffer.from(content).length;
|
|
12
|
+
}
|
|
13
|
+
return (content == null ? void 0 : content.length) || 0;
|
|
14
|
+
};
|
|
9
15
|
var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
|
|
10
16
|
var items = Object.values(bundle);
|
|
11
17
|
var assets = [];
|
|
@@ -13,16 +19,15 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
|
|
|
13
19
|
var moduleByFileName = {};
|
|
14
20
|
items.forEach(function (item) {
|
|
15
21
|
if (item.type === 'chunk') {
|
|
16
|
-
var _item$code;
|
|
17
22
|
assets.push({
|
|
18
23
|
name: item.fileName,
|
|
19
|
-
size: (
|
|
24
|
+
size: getByteSize(item.code)
|
|
20
25
|
});
|
|
21
26
|
var chunkId = item.name;
|
|
22
27
|
chunks.push({
|
|
23
28
|
id: chunkId,
|
|
24
29
|
entry: item.isEntry,
|
|
25
|
-
initial:
|
|
30
|
+
initial: item.isEntry,
|
|
26
31
|
files: [item.fileName],
|
|
27
32
|
names: [item.name]
|
|
28
33
|
});
|
|
@@ -41,11 +46,10 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
|
|
|
41
46
|
};
|
|
42
47
|
}
|
|
43
48
|
});
|
|
44
|
-
} else {
|
|
45
|
-
var _item$source;
|
|
49
|
+
} else if (item.type === 'asset') {
|
|
46
50
|
assets.push({
|
|
47
51
|
name: item.fileName,
|
|
48
|
-
size: (
|
|
52
|
+
size: getByteSize(item.source)
|
|
49
53
|
});
|
|
50
54
|
}
|
|
51
55
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup-plugin-webpack-stats.cjs.development.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport { OutputBundle } from 'rollup';\n\n// https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts\nexport type WebpackStatsFilteredAsset = {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredChunk {\n id: number | string;\n entry: boolean;\n initial: boolean;\n files?: Array<string>;\n names?: Array<string>;\n}\n\nexport interface WebpackStatsFilteredModule {\n name: string;\n size?: number;\n chunks: Array<string | number>;\n}\n\nexport interface WebpackStatsFilteredConcatenatedModule {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {\n modules?: Array<WebpackStatsFilteredConcatenatedModule>;\n}\n\nexport interface WebpackStatsFiltered {\n builtAt?: number;\n hash?: string;\n assets?: Array<WebpackStatsFilteredAsset>;\n chunks?: Array<WebpackStatsFilteredChunk>;\n modules?: Array<WebpackStatsFilteredRootModule>;\n}\n\nexport const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {\n const items = Object.values(bundle);\n\n const assets: Array<WebpackStatsFilteredAsset> = [];\n const chunks: Array<WebpackStatsFilteredChunk> = [];\n\n const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};\n\n items.forEach((item) => {\n if (item.type === 'chunk') {\n assets.push({\n name: item.fileName,\n size: item.code
|
|
1
|
+
{"version":3,"file":"rollup-plugin-webpack-stats.cjs.development.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport { OutputBundle } from 'rollup';\n\n// https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts\nexport type WebpackStatsFilteredAsset = {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredChunk {\n id: number | string;\n entry: boolean;\n initial: boolean;\n files?: Array<string>;\n names?: Array<string>;\n}\n\nexport interface WebpackStatsFilteredModule {\n name: string;\n size?: number;\n chunks: Array<string | number>;\n}\n\nexport interface WebpackStatsFilteredConcatenatedModule {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {\n modules?: Array<WebpackStatsFilteredConcatenatedModule>;\n}\n\nexport interface WebpackStatsFiltered {\n builtAt?: number;\n hash?: string;\n assets?: Array<WebpackStatsFilteredAsset>;\n chunks?: Array<WebpackStatsFilteredChunk>;\n modules?: Array<WebpackStatsFilteredRootModule>;\n}\n\nconst getByteSize = (content: string | Buffer): number => {\n if (typeof content === 'string') {\n return Buffer.from(content).length;\n }\n\n return content?.length || 0;\n};\n\nexport const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {\n const items = Object.values(bundle);\n\n const assets: Array<WebpackStatsFilteredAsset> = [];\n const chunks: Array<WebpackStatsFilteredChunk> = [];\n\n const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};\n\n items.forEach((item) => {\n if (item.type === 'chunk') {\n assets.push({\n name: item.fileName,\n size: getByteSize(item.code),\n });\n\n const chunkId = item.name;\n\n chunks.push({\n id: chunkId,\n entry: item.isEntry,\n initial: item.isEntry,\n files: [item.fileName],\n names: [item.name]\n });\n\n Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {\n const relativeModulePath = path.relative(process.cwd(), modulePath.replace('\\u0000', ''));\n\n const moduleEntry = moduleByFileName[relativeModulePath];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePath] = {\n name: relativeModulePath,\n size: moduleInfo.originalLength,\n chunks: [chunkId],\n };\n }\n });\n } else if (item.type === 'asset') {\n assets.push({\n name: item.fileName,\n size: getByteSize(item.source),\n });\n } else {\n // noop for unknown types\n }\n });\n\n const output = {\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n\n return output;\n};\n","import { Plugin } from 'rollup';\n\nimport { bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\nexport const webpackStats = (): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle);\n\n this.emitFile({\n type: 'asset',\n fileName: 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n"],"names":["getByteSize","content","Buffer","from","length","bundleToWebpackStats","bundle","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","name","fileName","size","code","chunkId","id","entry","isEntry","initial","files","names","entries","modules","modulePath","moduleInfo","relativeModulePath","path","relative","process","cwd","replace","moduleEntry","originalLength","source","output","NAME","webpackStats","generateBundle","_","emitFile","JSON","stringify"],"mappings":";;;;;;;;AAwCA,IAAMA,WAAW,GAAG,SAAdA,WAAW,CAAIC,OAAwB;EAC3C,IAAI,OAAOA,OAAO,KAAK,QAAQ,EA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MAAM,CAACK,IAAI,CAACK,OAAO,CAAC;SACjC,MAAM;UACLT,gBAAgB,CAACoB,kBAAkB,CAAC,GAAG;YACrCf,IAAI,EAAEe,kBAAkB;YACxBb,IAAI,EAAEY,UAAU,CAACQ,cAAc;YAC/B5B,MAAM,EAAE,CAACU,OAAO;WACjB;;OAEJ,CAAC;KACH,MAAM,IAAIP,IAAI,CAACC,IAAI,KAAK,OAAO,EAAE;MAChCL,MAAM,CAACM,IAAI,CAAC;QACVC,IAAI,EAAEH,IAAI,CAACI,QAAQ;QACnBC,IAAI,EAAEnB,WAAW,CAACc,IAAI,CAAC0B,MAAM;OAC9B,CAAC;;GAIL,CAAC;EAEF,IAAMC,MAAM,GAAG;IACb/B,MAAM,EAANA,MAAM;IACNC,MAAM,EAANA,MAAM;IACNkB,OAAO,EAAErB,MAAM,CAACC,MAAM,CAACG,gBAAgB;GACxC;EAED,OAAO6B,MAAM;AACf,CAAC;;ACrGD,IAAMC,IAAI,GAAG,cAAc;AAE3B,IAAaC,YAAY,GAAG,SAAfA,YAAY;EAAA,OAAkB;IACzC1B,IAAI,EAAEyB,IAAI;IACVE,cAAc,0BAACC,CAAC,EAAEvC,MAAM;MACtB,IAAMmC,MAAM,GAAGpC,oBAAoB,CAACC,MAAM,CAAC;MAE3C,IAAI,CAACwC,QAAQ,CAAC;QACZ/B,IAAI,EAAE,OAAO;QACbG,QAAQ,EAAE,oBAAoB;QAC9BsB,MAAM,EAAEO,IAAI,CAACC,SAAS,CAACP,MAAM;OAC9B,CAAC;;GAEL;AAAA,CAAC;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("node:path"))&&"object"==typeof e&&"default"in e?e.default:e;exports.webpackStats=function(){return{name:"webpackStats",generateBundle:function(e,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("node:path"))&&"object"==typeof e&&"default"in e?e.default:e,n=function(e){return"string"==typeof e?Buffer.from(e).length:(null==e?void 0:e.length)||0};exports.webpackStats=function(){return{name:"webpackStats",generateBundle:function(e,s){var a=function(e){var s=Object.values(e),a=[],i=[],r={};return s.forEach((function(e){if("chunk"===e.type){a.push({name:e.fileName,size:n(e.code)});var s=e.name;i.push({id:s,entry:e.isEntry,initial:e.isEntry,files:[e.fileName],names:[e.name]}),Object.entries(e.modules).forEach((function(e){var n=e[0],a=e[1],i=t.relative(process.cwd(),n.replace("\0","")),u=r[i];u?u.chunks.push(s):r[i]={name:i,size:a.originalLength,chunks:[s]}}))}else"asset"===e.type&&a.push({name:e.fileName,size:n(e.source)})})),{assets:a,chunks:i,modules:Object.values(r)}}(s);this.emitFile({type:"asset",fileName:"webpack-stats.json",source:JSON.stringify(a)})}}};
|
|
2
2
|
//# sourceMappingURL=rollup-plugin-webpack-stats.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup-plugin-webpack-stats.cjs.production.min.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"rollup-plugin-webpack-stats.cjs.production.min.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport { OutputBundle } from 'rollup';\n\n// https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts\nexport type WebpackStatsFilteredAsset = {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredChunk {\n id: number | string;\n entry: boolean;\n initial: boolean;\n files?: Array<string>;\n names?: Array<string>;\n}\n\nexport interface WebpackStatsFilteredModule {\n name: string;\n size?: number;\n chunks: Array<string | number>;\n}\n\nexport interface WebpackStatsFilteredConcatenatedModule {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {\n modules?: Array<WebpackStatsFilteredConcatenatedModule>;\n}\n\nexport interface WebpackStatsFiltered {\n builtAt?: number;\n hash?: string;\n assets?: Array<WebpackStatsFilteredAsset>;\n chunks?: Array<WebpackStatsFilteredChunk>;\n modules?: Array<WebpackStatsFilteredRootModule>;\n}\n\nconst getByteSize = (content: string | Buffer): number => {\n if (typeof content === 'string') {\n return Buffer.from(content).length;\n }\n\n return content?.length || 0;\n};\n\nexport const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {\n const items = Object.values(bundle);\n\n const assets: Array<WebpackStatsFilteredAsset> = [];\n const chunks: Array<WebpackStatsFilteredChunk> = [];\n\n const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};\n\n items.forEach((item) => {\n if (item.type === 'chunk') {\n assets.push({\n name: item.fileName,\n size: getByteSize(item.code),\n });\n\n const chunkId = item.name;\n\n chunks.push({\n id: chunkId,\n entry: item.isEntry,\n initial: item.isEntry,\n files: [item.fileName],\n names: [item.name]\n });\n\n Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {\n const relativeModulePath = path.relative(process.cwd(), modulePath.replace('\\u0000', ''));\n\n const moduleEntry = moduleByFileName[relativeModulePath];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePath] = {\n name: relativeModulePath,\n size: moduleInfo.originalLength,\n chunks: [chunkId],\n };\n }\n });\n } else if (item.type === 'asset') {\n assets.push({\n name: item.fileName,\n size: getByteSize(item.source),\n });\n } else {\n // noop for unknown types\n }\n });\n\n const output = {\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n\n return output;\n};\n","import { Plugin } from 'rollup';\n\nimport { bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\nexport const webpackStats = (): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle);\n\n this.emitFile({\n type: 'asset',\n fileName: 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n"],"names":["getByteSize","content","Buffer","from","length","name","generateBundle","_","bundle","output","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","fileName","size","code","chunkId","id","entry","isEntry","initial","files","names","entries","modules","modulePath","moduleInfo","relativeModulePath","path","relative","process","cwd","replace","moduleEntry","originalLength","source","bundleToWebpackStats","this","emitFile","JSON","stringify"],"mappings":"oJAwCMA,EAAc,SAACC,GACnB,MAAuB,iBAAZA,EACFC,OAAOC,KAAKF,GAASG,cAGvBH,SAAAA,EAASG,SAAU,wBCvCA,WAAH,MAAkB,CACzCC,KAHW,eAIXC,wBAAeC,EAAGC,GAChB,IAAMC,EDuC0B,SAACD,GACnC,IAAME,EAAQC,OAAOC,OAAOJ,GAEtBK,EAA2C,GAC3CC,EAA2C,GAE3CC,EAA+D,GAkDrE,OAhDAL,EAAMM,SAAQ,SAACC,GACb,GAAkB,UAAdA,EAAKC,KAAkB,CACzBL,EAAOM,KAAK,CACVd,KAAMY,EAAKG,SACXC,KAAMrB,EAAYiB,EAAKK,QAGzB,IAAMC,EAAUN,EAAKZ,KAErBS,EAAOK,KAAK,CACVK,GAAID,EACJE,MAAOR,EAAKS,QACZC,QAASV,EAAKS,QACdE,MAAO,CAACX,EAAKG,UACbS,MAAO,CAACZ,EAAKZ,QAGfM,OAAOmB,QAAQb,EAAKc,SAASf,SAAQ,gBAAEgB,OAAYC,OAC3CC,EAAqBC,EAAKC,SAASC,QAAQC,MAAON,EAAWO,QAAQ,KAAU,KAE/EC,EAAczB,EAAiBmB,GAEjCM,EACFA,EAAY1B,OAAOK,KAAKI,GAExBR,EAAiBmB,GAAsB,CACrC7B,KAAM6B,EACNb,KAAMY,EAAWQ,eACjB3B,OAAQ,CAACS,WAIQ,UAAdN,EAAKC,MACdL,EAAOM,KAAK,CACVd,KAAMY,EAAKG,SACXC,KAAMrB,EAAYiB,EAAKyB,aAOd,CACb7B,OAAAA,EACAC,OAAAA,EACAiB,QAASpB,OAAOC,OAAOG,IC5FR4B,CAAqBnC,GAEpCoC,KAAKC,SAAS,CACZ3B,KAAM,QACNE,SAAU,qBACVsB,OAAQI,KAAKC,UAAUtC"}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
|
|
3
|
+
var getByteSize = function getByteSize(content) {
|
|
4
|
+
if (typeof content === 'string') {
|
|
5
|
+
return Buffer.from(content).length;
|
|
6
|
+
}
|
|
7
|
+
return (content == null ? void 0 : content.length) || 0;
|
|
8
|
+
};
|
|
3
9
|
var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
|
|
4
10
|
var items = Object.values(bundle);
|
|
5
11
|
var assets = [];
|
|
@@ -7,16 +13,15 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
|
|
|
7
13
|
var moduleByFileName = {};
|
|
8
14
|
items.forEach(function (item) {
|
|
9
15
|
if (item.type === 'chunk') {
|
|
10
|
-
var _item$code;
|
|
11
16
|
assets.push({
|
|
12
17
|
name: item.fileName,
|
|
13
|
-
size: (
|
|
18
|
+
size: getByteSize(item.code)
|
|
14
19
|
});
|
|
15
20
|
var chunkId = item.name;
|
|
16
21
|
chunks.push({
|
|
17
22
|
id: chunkId,
|
|
18
23
|
entry: item.isEntry,
|
|
19
|
-
initial:
|
|
24
|
+
initial: item.isEntry,
|
|
20
25
|
files: [item.fileName],
|
|
21
26
|
names: [item.name]
|
|
22
27
|
});
|
|
@@ -35,11 +40,10 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
|
|
|
35
40
|
};
|
|
36
41
|
}
|
|
37
42
|
});
|
|
38
|
-
} else {
|
|
39
|
-
var _item$source;
|
|
43
|
+
} else if (item.type === 'asset') {
|
|
40
44
|
assets.push({
|
|
41
45
|
name: item.fileName,
|
|
42
|
-
size: (
|
|
46
|
+
size: getByteSize(item.source)
|
|
43
47
|
});
|
|
44
48
|
}
|
|
45
49
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup-plugin-webpack-stats.esm.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport { OutputBundle } from 'rollup';\n\n// https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts\nexport type WebpackStatsFilteredAsset = {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredChunk {\n id: number | string;\n entry: boolean;\n initial: boolean;\n files?: Array<string>;\n names?: Array<string>;\n}\n\nexport interface WebpackStatsFilteredModule {\n name: string;\n size?: number;\n chunks: Array<string | number>;\n}\n\nexport interface WebpackStatsFilteredConcatenatedModule {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {\n modules?: Array<WebpackStatsFilteredConcatenatedModule>;\n}\n\nexport interface WebpackStatsFiltered {\n builtAt?: number;\n hash?: string;\n assets?: Array<WebpackStatsFilteredAsset>;\n chunks?: Array<WebpackStatsFilteredChunk>;\n modules?: Array<WebpackStatsFilteredRootModule>;\n}\n\nexport const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {\n const items = Object.values(bundle);\n\n const assets: Array<WebpackStatsFilteredAsset> = [];\n const chunks: Array<WebpackStatsFilteredChunk> = [];\n\n const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};\n\n items.forEach((item) => {\n if (item.type === 'chunk') {\n assets.push({\n name: item.fileName,\n size: item.code
|
|
1
|
+
{"version":3,"file":"rollup-plugin-webpack-stats.esm.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport { OutputBundle } from 'rollup';\n\n// https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts\nexport type WebpackStatsFilteredAsset = {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredChunk {\n id: number | string;\n entry: boolean;\n initial: boolean;\n files?: Array<string>;\n names?: Array<string>;\n}\n\nexport interface WebpackStatsFilteredModule {\n name: string;\n size?: number;\n chunks: Array<string | number>;\n}\n\nexport interface WebpackStatsFilteredConcatenatedModule {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {\n modules?: Array<WebpackStatsFilteredConcatenatedModule>;\n}\n\nexport interface WebpackStatsFiltered {\n builtAt?: number;\n hash?: string;\n assets?: Array<WebpackStatsFilteredAsset>;\n chunks?: Array<WebpackStatsFilteredChunk>;\n modules?: Array<WebpackStatsFilteredRootModule>;\n}\n\nconst getByteSize = (content: string | Buffer): number => {\n if (typeof content === 'string') {\n return Buffer.from(content).length;\n }\n\n return content?.length || 0;\n};\n\nexport const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {\n const items = Object.values(bundle);\n\n const assets: Array<WebpackStatsFilteredAsset> = [];\n const chunks: Array<WebpackStatsFilteredChunk> = [];\n\n const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};\n\n items.forEach((item) => {\n if (item.type === 'chunk') {\n assets.push({\n name: item.fileName,\n size: getByteSize(item.code),\n });\n\n const chunkId = item.name;\n\n chunks.push({\n id: chunkId,\n entry: item.isEntry,\n initial: item.isEntry,\n files: [item.fileName],\n names: [item.name]\n });\n\n Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {\n const relativeModulePath = path.relative(process.cwd(), modulePath.replace('\\u0000', ''));\n\n const moduleEntry = moduleByFileName[relativeModulePath];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePath] = {\n name: relativeModulePath,\n size: moduleInfo.originalLength,\n chunks: [chunkId],\n };\n }\n });\n } else if (item.type === 'asset') {\n assets.push({\n name: item.fileName,\n size: getByteSize(item.source),\n });\n } else {\n // noop for unknown types\n }\n });\n\n const output = {\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n\n return output;\n};\n","import { Plugin } from 'rollup';\n\nimport { bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\nexport const webpackStats = (): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle);\n\n this.emitFile({\n type: 'asset',\n fileName: 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n"],"names":["getByteSize","content","Buffer","from","length","bundleToWebpackStats","bundle","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","name","fileName","size","code","chunkId","id","entry","isEntry","initial","files","names","entries","modules","modulePath","moduleInfo","relativeModulePath","path","relative","process","cwd","replace","moduleEntry","originalLength","source","output","NAME","webpackStats","generateBundle","_","emitFile","JSON","stringify"],"mappings":";;AAwCA,IAAMA,WAAW,GAAG,SAAdA,WAAW,CAAIC,OAAwB;EAC3C,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;IAC/B,OAAOC,MAAM,CAACC,IAAI,CAACF,OAAO,CAAC,CAACG,MAAM;;EAGpC,OAAO,CAAAH,OAAO,oBAAPA,OAAO,CAAEG,MAAM,KAAI,CAAC;AAC7B,CAAC;AAEM,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAoB,CAAIC,MAAoB;EACvD,IAAMC,KAAK,GAAGC,MAAM,CAACC,MAAM,CAACH,MAAM,CAAC;EAEnC,IAAMI,MAAM,GAAqC,EAAE;EACnD,IAAMC,MAAM,GAAqC,EAAE;EAEnD,IAAMC,gBAAgB,GAA+C,EAAE;EAEvEL,KAAK,CAACM,OAAO,CAAC,UAACC,IAAI;IACjB,IAAIA,IAAI,CAACC,IAAI,KAAK,OAAO,EAAE;MACzBL,MAAM,CAACM,IAAI,CAAC;QACVC,IAAI,EAAEH,IAAI,CAACI,QAAQ;QACnBC,IAAI,EAAEnB,WAAW,CAACc,IAAI,CAACM,IAAI;OAC5B,CAAC;MAEF,IAAMC,OAAO,GAAGP,IAAI,CAACG,IAAI;MAEzBN,MAAM,CAACK,IAAI,CAAC;QACVM,EAAE,EAAED,OAAO;QACXE,KAAK,EAAET,IAAI,CAACU,OAAO;QACnBC,OAAO,EAAEX,IAAI,CAACU,OAAO;QACrBE,KAAK,EAAE,CAACZ,IAAI,CAACI,QAAQ,CAAC;QACtBS,KAAK,EAAE,CAACb,IAAI,CAACG,IAAI;OAClB,CAAC;MAEFT,MAAM,CAACoB,OAA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I,CAACC,SAAS,CAACP,MAAM;OAC9B,CAAC;;GAEL;AAAA,CAAC;;;;"}
|
package/package.json
CHANGED
package/src/transform.ts
CHANGED
|
@@ -38,6 +38,14 @@ export interface WebpackStatsFiltered {
|
|
|
38
38
|
modules?: Array<WebpackStatsFilteredRootModule>;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
const getByteSize = (content: string | Buffer): number => {
|
|
42
|
+
if (typeof content === 'string') {
|
|
43
|
+
return Buffer.from(content).length;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return content?.length || 0;
|
|
47
|
+
};
|
|
48
|
+
|
|
41
49
|
export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {
|
|
42
50
|
const items = Object.values(bundle);
|
|
43
51
|
|
|
@@ -50,7 +58,7 @@ export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered
|
|
|
50
58
|
if (item.type === 'chunk') {
|
|
51
59
|
assets.push({
|
|
52
60
|
name: item.fileName,
|
|
53
|
-
size: item.code
|
|
61
|
+
size: getByteSize(item.code),
|
|
54
62
|
});
|
|
55
63
|
|
|
56
64
|
const chunkId = item.name;
|
|
@@ -58,7 +66,7 @@ export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered
|
|
|
58
66
|
chunks.push({
|
|
59
67
|
id: chunkId,
|
|
60
68
|
entry: item.isEntry,
|
|
61
|
-
initial:
|
|
69
|
+
initial: item.isEntry,
|
|
62
70
|
files: [item.fileName],
|
|
63
71
|
names: [item.name]
|
|
64
72
|
});
|
|
@@ -78,11 +86,13 @@ export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered
|
|
|
78
86
|
};
|
|
79
87
|
}
|
|
80
88
|
});
|
|
81
|
-
} else {
|
|
89
|
+
} else if (item.type === 'asset') {
|
|
82
90
|
assets.push({
|
|
83
91
|
name: item.fileName,
|
|
84
|
-
size: item.source
|
|
92
|
+
size: getByteSize(item.source),
|
|
85
93
|
});
|
|
94
|
+
} else {
|
|
95
|
+
// noop for unknown types
|
|
86
96
|
}
|
|
87
97
|
});
|
|
88
98
|
|