rollup-plugin-webpack-stats 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Vio
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 ADDED
@@ -0,0 +1,33 @@
1
+ # rollup-plugin-webpack-stats
2
+
3
+ > > **Warning**
4
+ > Under active development
5
+
6
+ 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
+
8
+ ## Install
9
+
10
+ ```shell
11
+ npm install --dev rollup-plugin-webpack-stats
12
+ ```
13
+
14
+ or
15
+
16
+ ```shell
17
+ yarn add --dev rollup-plugin-webpack-stats
18
+ ```
19
+
20
+ ## Configure
21
+
22
+
23
+ ```js
24
+ // rollup.config.js
25
+ const { webpackStats } = require('rollup-plugin-webpack-stats');
26
+
27
+ module.exports = {
28
+ plugins: [
29
+ // add it as the last plugin
30
+ webpackStats(),
31
+ ],
32
+ };
33
+ ```
@@ -0,0 +1,2 @@
1
+ import { Plugin } from 'rollup';
2
+ export declare const webpackStats: () => Plugin;
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./rollup-plugin-webpack-stats.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./rollup-plugin-webpack-stats.cjs.development.js')
8
+ }
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
+
7
+ var path = _interopDefault(require('node:path'));
8
+
9
+ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
10
+ var items = Object.values(bundle);
11
+ var assets = [];
12
+ var chunks = [];
13
+ var moduleByFileName = {};
14
+ items.forEach(function (item) {
15
+ if (item.type === 'chunk') {
16
+ var _item$code;
17
+ assets.push({
18
+ name: item.fileName,
19
+ size: (_item$code = item.code) == null ? void 0 : _item$code.length
20
+ });
21
+ var chunkId = item.name;
22
+ chunks.push({
23
+ id: chunkId,
24
+ entry: item.isEntry,
25
+ initial: false,
26
+ files: [item.fileName],
27
+ names: [item.name]
28
+ });
29
+ Object.entries(item.modules).forEach(function (_ref) {
30
+ var modulePath = _ref[0],
31
+ moduleInfo = _ref[1];
32
+ var relativeModulePath = path.relative(process.cwd(), modulePath.replace("\0", ''));
33
+ var moduleEntry = moduleByFileName[relativeModulePath];
34
+ if (moduleEntry) {
35
+ moduleEntry.chunks.push(chunkId);
36
+ } else {
37
+ moduleByFileName[relativeModulePath] = {
38
+ name: relativeModulePath,
39
+ size: moduleInfo.originalLength,
40
+ chunks: [chunkId]
41
+ };
42
+ }
43
+ });
44
+ } else {
45
+ var _item$source;
46
+ assets.push({
47
+ name: item.fileName,
48
+ size: (_item$source = item.source) == null ? void 0 : _item$source.length
49
+ });
50
+ }
51
+ });
52
+ var output = {
53
+ assets: assets,
54
+ chunks: chunks,
55
+ modules: Object.values(moduleByFileName)
56
+ };
57
+ return output;
58
+ };
59
+
60
+ var NAME = 'webpackStats';
61
+ var webpackStats = function webpackStats() {
62
+ return {
63
+ name: NAME,
64
+ generateBundle: function generateBundle(_, bundle) {
65
+ var output = bundleToWebpackStats(bundle);
66
+ this.emitFile({
67
+ type: 'asset',
68
+ fileName: 'webpack-stats.json',
69
+ source: JSON.stringify(output)
70
+ });
71
+ }
72
+ };
73
+ };
74
+
75
+ exports.webpackStats = webpackStats;
76
+ //# sourceMappingURL=rollup-plugin-webpack-stats.cjs.development.js.map
@@ -0,0 +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?.length,\n });\n\n const chunkId = item.name;\n\n chunks.push({\n id: chunkId,\n entry: item.isEntry,\n initial: false,\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 {\n assets.push({\n name: item.fileName,\n size: item.source?.length,\n });\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":["bundleToWebpackStats","bundle","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","name","fileName","size","code","length","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":";;;;;;;;AAwCO,IAAMA,oBAAoB,GAAG,SAAvBA,oBAAoB,CAAIC,MAAoB;EACvD,IAAMC,KAAK,GAAGC,MAAM,CAACC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,IAAI,CAAC;QACVC,IAAI,EAAEH,IAAI,CAACI,QAAQ;QACnBC,IAAI,kBAAEL,IAAI,CAAC2B,MAAM,qBAAX,aAAapB;OACpB,CAAC;;GAEL,CAAC;EAEF,IAAMqB,MAAM,GAAG;IACbhC,MAAM,EAANA,MAAM;IACNC,MAAM,EAANA,MAAM;IACNmB,OAAO,EAAEtB,MAAM,CAACC,MAAM,CAACG,gBAAgB;GACxC;EAED,OAAO8B,MAAM;AACf,CAAC;;AC3FD,IAAMC,IAAI,GAAG,cAAc;AAE3B,IAAaC,YAAY,GAAG,SAAfA,YAAY;EAAA,OAAkB;IACzC3B,IAAI,EAAE0B,IAAI;IACVE,cAAc,0BAACC,CAAC,EAAExC,MAAM;MACtB,IAAMoC,MAAM,GAAGrC,oBAAoB,CAACC,MAAM,CAAC;MAE3C,IAAI,CAACyC,QAAQ,CAAC;QACZhC,IAAI,EAAE,OAAO;QACbG,QAAQ,EAAE,oBAAoB;QAC9BuB,MAAM,EAAEO,IAAI,CAACC,SAAS,CAACP,MAAM;OAC9B,CAAC;;GAEL;AAAA,CAAC;;;;"}
@@ -0,0 +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,n){var s=function(e){var n=Object.values(e),s=[],a=[],i={};return n.forEach((function(e){if("chunk"===e.type){var n;s.push({name:e.fileName,size:null==(n=e.code)?void 0:n.length});var r=e.name;a.push({id:r,entry:e.isEntry,initial:!1,files:[e.fileName],names:[e.name]}),Object.entries(e.modules).forEach((function(e){var n=e[0],s=e[1],a=t.relative(process.cwd(),n.replace("\0","")),u=i[a];u?u.chunks.push(r):i[a]={name:a,size:s.originalLength,chunks:[r]}}))}else{var u;s.push({name:e.fileName,size:null==(u=e.source)?void 0:u.length})}})),{assets:s,chunks:a,modules:Object.values(i)}}(n);this.emitFile({type:"asset",fileName:"webpack-stats.json",source:JSON.stringify(s)})}}};
2
+ //# sourceMappingURL=rollup-plugin-webpack-stats.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup-plugin-webpack-stats.cjs.production.min.js","sources":["../src/index.ts","../src/transform.ts"],"sourcesContent":["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","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?.length,\n });\n\n const chunkId = item.name;\n\n chunks.push({\n id: chunkId,\n entry: item.isEntry,\n initial: false,\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 {\n assets.push({\n name: item.fileName,\n size: item.source?.length,\n });\n }\n });\n\n const output = {\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n\n return output;\n};\n"],"names":["name","generateBundle","_","bundle","output","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","fileName","size","code","_item$code","length","chunkId","id","entry","isEntry","initial","files","names","entries","modules","modulePath","moduleInfo","relativeModulePath","path","relative","process","cwd","replace","moduleEntry","originalLength","source","_item$source","bundleToWebpackStats","this","emitFile","JSON","stringify"],"mappings":"yKAM4B,WAAH,MAAkB,CACzCA,KAHW,eAIXC,wBAAeC,EAAGC,GAChB,IAAMC,EC+B0B,SAACD,GACnC,IAAME,EAAQC,OAAOC,OAAOJ,GAEtBK,EAA2C,GAC3CC,EAA2C,GAE3CC,EAA+D,GAgDrE,OA9CAL,EAAMM,SAAQ,SAACC,GACb,GAAkB,UAAdA,EAAKC,KAAkB,CAAA,MACzBL,EAAOM,KAAK,CACVd,KAAMY,EAAKG,SACXC,cAAMJ,EAAKK,aAALC,EAAWC,SAGnB,IAAMC,EAAUR,EAAKZ,KAErBS,EAAOK,KAAK,CACVO,GAAID,EACJE,MAAOV,EAAKW,QACZC,SAAS,EACTC,MAAO,CAACb,EAAKG,UACbW,MAAO,CAACd,EAAKZ,QAGfM,OAAOqB,QAAQf,EAAKgB,SAASjB,SAAQ,gBAAEkB,OAAYC,OAC3CC,EAAqBC,EAAKC,SAASC,QAAQC,MAAON,EAAWO,QAAQ,KAAU,KAE/EC,EAAc3B,EAAiBqB,GAEjCM,EACFA,EAAY5B,OAAOK,KAAKM,GAExBV,EAAiBqB,GAAsB,CACrC/B,KAAM+B,EACNf,KAAMc,EAAWQ,eACjB7B,OAAQ,CAACW,WAIV,CAAA,MACLZ,EAAOM,KAAK,CACVd,KAAMY,EAAKG,SACXC,cAAMJ,EAAK2B,eAALC,EAAarB,aAKV,CACbX,OAAAA,EACAC,OAAAA,EACAmB,QAAStB,OAAOC,OAAOG,IDlFR+B,CAAqBtC,GAEpCuC,KAAKC,SAAS,CACZ9B,KAAM,QACNE,SAAU,qBACVwB,OAAQK,KAAKC,UAAUzC"}
@@ -0,0 +1,70 @@
1
+ import path from 'node:path';
2
+
3
+ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
4
+ var items = Object.values(bundle);
5
+ var assets = [];
6
+ var chunks = [];
7
+ var moduleByFileName = {};
8
+ items.forEach(function (item) {
9
+ if (item.type === 'chunk') {
10
+ var _item$code;
11
+ assets.push({
12
+ name: item.fileName,
13
+ size: (_item$code = item.code) == null ? void 0 : _item$code.length
14
+ });
15
+ var chunkId = item.name;
16
+ chunks.push({
17
+ id: chunkId,
18
+ entry: item.isEntry,
19
+ initial: false,
20
+ files: [item.fileName],
21
+ names: [item.name]
22
+ });
23
+ Object.entries(item.modules).forEach(function (_ref) {
24
+ var modulePath = _ref[0],
25
+ moduleInfo = _ref[1];
26
+ var relativeModulePath = path.relative(process.cwd(), modulePath.replace("\0", ''));
27
+ var moduleEntry = moduleByFileName[relativeModulePath];
28
+ if (moduleEntry) {
29
+ moduleEntry.chunks.push(chunkId);
30
+ } else {
31
+ moduleByFileName[relativeModulePath] = {
32
+ name: relativeModulePath,
33
+ size: moduleInfo.originalLength,
34
+ chunks: [chunkId]
35
+ };
36
+ }
37
+ });
38
+ } else {
39
+ var _item$source;
40
+ assets.push({
41
+ name: item.fileName,
42
+ size: (_item$source = item.source) == null ? void 0 : _item$source.length
43
+ });
44
+ }
45
+ });
46
+ var output = {
47
+ assets: assets,
48
+ chunks: chunks,
49
+ modules: Object.values(moduleByFileName)
50
+ };
51
+ return output;
52
+ };
53
+
54
+ var NAME = 'webpackStats';
55
+ var webpackStats = function webpackStats() {
56
+ return {
57
+ name: NAME,
58
+ generateBundle: function generateBundle(_, bundle) {
59
+ var output = bundleToWebpackStats(bundle);
60
+ this.emitFile({
61
+ type: 'asset',
62
+ fileName: 'webpack-stats.json',
63
+ source: JSON.stringify(output)
64
+ });
65
+ }
66
+ };
67
+ };
68
+
69
+ export { webpackStats };
70
+ //# sourceMappingURL=rollup-plugin-webpack-stats.esm.js.map
@@ -0,0 +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?.length,\n });\n\n const chunkId = item.name;\n\n chunks.push({\n id: chunkId,\n entry: item.isEntry,\n initial: false,\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 {\n assets.push({\n name: item.fileName,\n size: item.source?.length,\n });\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":["bundleToWebpackStats","bundle","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","name","fileName","size","code","length","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":";;AAwCO,IAAMA,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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,GAAG;IACbhC,MAAM,EAANA,MAAM;IACNC,MAAM,EAANA,MAAM;IACNmB,OAAO,EAAEtB,MAAM,CAACC,MAAM,CAACG,gBAAgB;GACxC;EAED,OAAO8B,MAAM;AACf,CAAC;;AC3FD,IAAMC,IAAI,GAAG,cAAc;AAE3B,IAAaC,YAAY,GAAG,SAAfA,YAAY;EAAA,OAAkB;IACzC3B,IAAI,EAAE0B,IAAI;IACVE,cAAc,0BAACC,CAAC,EAAExC,MAAM;MACtB,IAAMoC,MAAM,GAAGrC,oBAAoB,CAACC,MAAM,CAAC;MAE3C,IAAI,CAACyC,QAAQ,CAAC;QACZhC,IAAI,EAAE,OAAO;QACbG,QAAQ,EAAE,oBAAoB;QAC9BuB,MAAM,EAAEO,IAAI,CAACC,SAAS,CAACP,MAAM;OAC9B,CAAC;;GAEL;AAAA,CAAC;;;;"}
@@ -0,0 +1,32 @@
1
+ import { OutputBundle } from 'rollup';
2
+ export declare type WebpackStatsFilteredAsset = {
3
+ name: string;
4
+ size?: number;
5
+ };
6
+ export interface WebpackStatsFilteredChunk {
7
+ id: number | string;
8
+ entry: boolean;
9
+ initial: boolean;
10
+ files?: Array<string>;
11
+ names?: Array<string>;
12
+ }
13
+ export interface WebpackStatsFilteredModule {
14
+ name: string;
15
+ size?: number;
16
+ chunks: Array<string | number>;
17
+ }
18
+ export interface WebpackStatsFilteredConcatenatedModule {
19
+ name: string;
20
+ size?: number;
21
+ }
22
+ export interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {
23
+ modules?: Array<WebpackStatsFilteredConcatenatedModule>;
24
+ }
25
+ export interface WebpackStatsFiltered {
26
+ builtAt?: number;
27
+ hash?: string;
28
+ assets?: Array<WebpackStatsFilteredAsset>;
29
+ chunks?: Array<WebpackStatsFilteredChunk>;
30
+ modules?: Array<WebpackStatsFilteredRootModule>;
31
+ }
32
+ export declare const bundleToWebpackStats: (bundle: OutputBundle) => WebpackStatsFiltered;
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "rollup-plugin-webpack-stats",
3
+ "version": "0.0.1",
4
+ "license": "MIT",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "src"
10
+ ],
11
+ "engines": {
12
+ "node": ">=14"
13
+ },
14
+ "scripts": {
15
+ "start": "tsdx watch",
16
+ "build": "tsdx build",
17
+ "test": "tsdx test",
18
+ "lint": "tsdx lint",
19
+ "prepare": "tsdx build",
20
+ "analyze": "size-limit --why"
21
+ },
22
+ "husky": {
23
+ "hooks": {
24
+ "pre-commit": "tsdx lint"
25
+ }
26
+ },
27
+ "prettier": {
28
+ "printWidth": 80,
29
+ "semi": true,
30
+ "singleQuote": true,
31
+ "trailingComma": "es5"
32
+ },
33
+ "author": "Vio",
34
+ "module": "dist/rollup-plugin-webpack-stats.esm.js",
35
+ "devDependencies": {
36
+ "husky": "^8.0.3",
37
+ "rollup": "^1.32.1",
38
+ "size-limit": "^8.1.0",
39
+ "tsdx": "^0.14.1",
40
+ "tslib": "^2.4.1",
41
+ "typescript": "^4.9.4"
42
+ },
43
+ "peerDependencies": {
44
+ "rollup": "^1.0.0"
45
+ }
46
+ }
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { Plugin } from 'rollup';
2
+
3
+ import { bundleToWebpackStats } from './transform';
4
+
5
+ const NAME = 'webpackStats';
6
+
7
+ export const webpackStats = (): Plugin => ({
8
+ name: NAME,
9
+ generateBundle(_, bundle) {
10
+ const output = bundleToWebpackStats(bundle);
11
+
12
+ this.emitFile({
13
+ type: 'asset',
14
+ fileName: 'webpack-stats.json',
15
+ source: JSON.stringify(output),
16
+ });
17
+ },
18
+ });
@@ -0,0 +1,96 @@
1
+ import path from 'node:path';
2
+ import { OutputBundle } from 'rollup';
3
+
4
+ // https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts
5
+ export type WebpackStatsFilteredAsset = {
6
+ name: string;
7
+ size?: number;
8
+ }
9
+
10
+ export interface WebpackStatsFilteredChunk {
11
+ id: number | string;
12
+ entry: boolean;
13
+ initial: boolean;
14
+ files?: Array<string>;
15
+ names?: Array<string>;
16
+ }
17
+
18
+ export interface WebpackStatsFilteredModule {
19
+ name: string;
20
+ size?: number;
21
+ chunks: Array<string | number>;
22
+ }
23
+
24
+ export interface WebpackStatsFilteredConcatenatedModule {
25
+ name: string;
26
+ size?: number;
27
+ }
28
+
29
+ export interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {
30
+ modules?: Array<WebpackStatsFilteredConcatenatedModule>;
31
+ }
32
+
33
+ export interface WebpackStatsFiltered {
34
+ builtAt?: number;
35
+ hash?: string;
36
+ assets?: Array<WebpackStatsFilteredAsset>;
37
+ chunks?: Array<WebpackStatsFilteredChunk>;
38
+ modules?: Array<WebpackStatsFilteredRootModule>;
39
+ }
40
+
41
+ export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {
42
+ const items = Object.values(bundle);
43
+
44
+ const assets: Array<WebpackStatsFilteredAsset> = [];
45
+ const chunks: Array<WebpackStatsFilteredChunk> = [];
46
+
47
+ const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};
48
+
49
+ items.forEach((item) => {
50
+ if (item.type === 'chunk') {
51
+ assets.push({
52
+ name: item.fileName,
53
+ size: item.code?.length,
54
+ });
55
+
56
+ const chunkId = item.name;
57
+
58
+ chunks.push({
59
+ id: chunkId,
60
+ entry: item.isEntry,
61
+ initial: false,
62
+ files: [item.fileName],
63
+ names: [item.name]
64
+ });
65
+
66
+ Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {
67
+ const relativeModulePath = path.relative(process.cwd(), modulePath.replace('\u0000', ''));
68
+
69
+ const moduleEntry = moduleByFileName[relativeModulePath];
70
+
71
+ if (moduleEntry) {
72
+ moduleEntry.chunks.push(chunkId);
73
+ } else {
74
+ moduleByFileName[relativeModulePath] = {
75
+ name: relativeModulePath,
76
+ size: moduleInfo.originalLength,
77
+ chunks: [chunkId],
78
+ };
79
+ }
80
+ });
81
+ } else {
82
+ assets.push({
83
+ name: item.fileName,
84
+ size: item.source?.length,
85
+ });
86
+ }
87
+ });
88
+
89
+ const output = {
90
+ assets,
91
+ chunks,
92
+ modules: Object.values(moduleByFileName),
93
+ };
94
+
95
+ return output;
96
+ };