rollup-plugin-webpack-stats 0.0.2 → 0.0.3

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/dist/index.d.ts CHANGED
@@ -1,2 +1,11 @@
1
1
  import { Plugin } from 'rollup';
2
- export declare const webpackStats: () => Plugin;
2
+ import { BundleTransformOptions } from './transform';
3
+ interface WebpackStatsOptions extends BundleTransformOptions {
4
+ /**
5
+ * JSON file output fileName
6
+ * default: webpack-stats.json
7
+ */
8
+ fileName?: string;
9
+ }
10
+ export declare const webpackStats: (options?: WebpackStatsOptions) => Plugin;
11
+ export {};
@@ -6,13 +6,31 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
6
6
 
7
7
  var path = _interopDefault(require('node:path'));
8
8
 
9
+ function _extends() {
10
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
11
+ for (var i = 1; i < arguments.length; i++) {
12
+ var source = arguments[i];
13
+ for (var key in source) {
14
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
15
+ target[key] = source[key];
16
+ }
17
+ }
18
+ }
19
+ return target;
20
+ };
21
+ return _extends.apply(this, arguments);
22
+ }
23
+
9
24
  var getByteSize = function getByteSize(content) {
10
25
  if (typeof content === 'string') {
11
26
  return Buffer.from(content).length;
12
27
  }
13
28
  return (content == null ? void 0 : content.length) || 0;
14
29
  };
15
- var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
30
+ var bundleToWebpackStats = function bundleToWebpackStats(bundle, customOptions) {
31
+ var options = _extends({
32
+ moduleOriginalSize: false
33
+ }, customOptions);
16
34
  var items = Object.values(bundle);
17
35
  var assets = [];
18
36
  var chunks = [];
@@ -27,7 +45,7 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
27
45
  chunks.push({
28
46
  id: chunkId,
29
47
  entry: item.isEntry,
30
- initial: item.isEntry,
48
+ initial: !item.isDynamicEntry,
31
49
  files: [item.fileName],
32
50
  names: [item.name]
33
51
  });
@@ -41,7 +59,7 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
41
59
  } else {
42
60
  moduleByFileName[relativeModulePath] = {
43
61
  name: relativeModulePath,
44
- size: moduleInfo.originalLength,
62
+ size: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength,
45
63
  chunks: [chunkId]
46
64
  };
47
65
  }
@@ -62,14 +80,18 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
62
80
  };
63
81
 
64
82
  var NAME = 'webpackStats';
65
- var webpackStats = function webpackStats() {
83
+ var webpackStats = function webpackStats(options) {
84
+ if (options === void 0) {
85
+ options = {};
86
+ }
66
87
  return {
67
88
  name: NAME,
68
89
  generateBundle: function generateBundle(_, bundle) {
69
- var output = bundleToWebpackStats(bundle);
90
+ var _options;
91
+ var output = bundleToWebpackStats(bundle, options);
70
92
  this.emitFile({
71
93
  type: 'asset',
72
- fileName: 'webpack-stats.json',
94
+ fileName: ((_options = options) == null ? void 0 : _options.fileName) || 'webpack-stats.json',
73
95
  source: JSON.stringify(output)
74
96
  });
75
97
  }
@@ -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\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,OAAO,CAACd,IAAI,CAACe,OAAO,CAAC,CAAChB,OAAO,CAAC;Y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CAAC;;;;"}
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 type BundleTransformOptions = {\n /**\n * Extract module original size or rendered size\n * default: false\n */\n moduleOriginalSize?: boolean;\n};\n\nexport const bundleToWebpackStats = (bundle: OutputBundle, customOptions?: BundleTransformOptions): WebpackStatsFiltered => {\n const options = {\n moduleOriginalSize: false,\n ...customOptions,\n };\n\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.isDynamicEntry,\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: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength,\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 { BundleTransformOptions, bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\ninterface WebpackStatsOptions extends BundleTransformOptions {\n /**\n * JSON file output fileName\n * default: webpack-stats.json\n */\n fileName?: string;\n}\n\nexport const webpackStats = (options: WebpackStatsOptions = {}): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle, options);\n\n this.emitFile({\n type: 'asset',\n fileName: options?.fileName || 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n"],"names":["getByteSize","content","Buffer","from","length","bundleToWebpackStats","bundle","customOptions","options","moduleOriginalSize","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","name","fileName","size","code","chunkId","id","entry","isEntry","initial","isDynamicEntry","files","names","entries","modules","modulePath","moduleInfo","relativeModulePath","path","relative","process","cwd","replace","moduleEntry","originalLength","renderedLength","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,CA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"))&&"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)})}}};
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;function n(){return(n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}var i=function(e){return"string"==typeof e?Buffer.from(e).length:(null==e?void 0:e.length)||0};exports.webpackStats=function(e){return void 0===e&&(e={}),{name:"webpackStats",generateBundle:function(r,a){var s,u=function(e,r){var a=n({moduleOriginalSize:!1},r),s=Object.values(e),u=[],o=[],l={};return s.forEach((function(e){if("chunk"===e.type){u.push({name:e.fileName,size:i(e.code)});var n=e.name;o.push({id:n,entry:e.isEntry,initial:!e.isDynamicEntry,files:[e.fileName],names:[e.name]}),Object.entries(e.modules).forEach((function(e){var i=e[0],r=e[1],s=t.relative(process.cwd(),i.replace("\0","")),u=l[s];u?u.chunks.push(n):l[s]={name:s,size:a.moduleOriginalSize?r.originalLength:r.renderedLength,chunks:[n]}}))}else"asset"===e.type&&u.push({name:e.fileName,size:i(e.source)})})),{assets:u,chunks:o,modules:Object.values(l)}}(a,e);this.emitFile({type:"asset",fileName:(null==(s=e)?void 0:s.fileName)||"webpack-stats.json",source:JSON.stringify(u)})}}};
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/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
+ {"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 type BundleTransformOptions = {\n /**\n * Extract module original size or rendered size\n * default: false\n */\n moduleOriginalSize?: boolean;\n};\n\nexport const bundleToWebpackStats = (bundle: OutputBundle, customOptions?: BundleTransformOptions): WebpackStatsFiltered => {\n const options = {\n moduleOriginalSize: false,\n ...customOptions,\n };\n\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.isDynamicEntry,\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: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength,\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 { BundleTransformOptions, bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\ninterface WebpackStatsOptions extends BundleTransformOptions {\n /**\n * JSON file output fileName\n * default: webpack-stats.json\n */\n fileName?: string;\n}\n\nexport const webpackStats = (options: WebpackStatsOptions = {}): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle, options);\n\n this.emitFile({\n type: 'asset',\n fileName: options?.fileName || 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n"],"names":["getByteSize","content","Buffer","from","length","options","name","generateBundle","_","bundle","output","customOptions","moduleOriginalSize","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","fileName","size","code","chunkId","id","entry","isEntry","initial","isDynamicEntry","files","names","entries","modules","modulePath","moduleInfo","relativeModulePath","path","relative","process","cwd","replace","moduleEntry","originalLength","renderedLength","source","bundleToWebpackStats","this","emitFile","_options","JSON","stringify"],"mappings":"uXAwCA,IAAMA,EAAc,SAACC,GACnB,MAAuB,iBAAZA,EACFC,OAAOC,KAAKF,GAASG,cAGvBH,SAAAA,EAASG,SAAU,wBC/BA,SAACC,GAAiC,gBAAjCA,IAAAA,EAA+B,IAAgB,CAC1EC,KAXW,eAYXC,wBAAeC,EAAGC,SACVC,EDuC0B,SAACD,EAAsBE,GACzD,IAAMN,KACJO,oBAAoB,GACjBD,GAGCE,EAAQC,OAAOC,OAAON,GAEtBO,EAA2C,GAC3CC,EAA2C,GAE3CC,EAA+D,GAkDrE,OAhDAL,EAAMM,SAAQ,SAACC,GACb,GAAkB,UAAdA,EAAKC,KAAkB,CACzBL,EAAOM,KAAK,CACVhB,KAAMc,EAAKG,SACXC,KAAMxB,EAAYoB,EAAKK,QAGzB,IAAMC,EAAUN,EAAKd,KAErBW,EAAOK,KAAK,CACVK,GAAID,EACJE,MAAOR,EAAKS,QACZC,SAAUV,EAAKW,eACfC,MAAO,CAACZ,EAAKG,UACbU,MAAO,CAACb,EAAKd,QAGfQ,OAAOoB,QAAQd,EAAKe,SAAShB,SAAQ,gBAAEiB,OAAYC,OAC3CC,EAAqBC,EAAKC,SAASC,QAAQC,MAAON,EAAWO,QAAQ,KAAU,KAE/EC,EAAc1B,EAAiBoB,GAEjCM,EACFA,EAAY3B,OAAOK,KAAKI,GAExBR,EAAiBoB,GAAsB,CACrChC,KAAMgC,EACNd,KAAMnB,EAAQO,mBAAqByB,EAAWQ,eAAiBR,EAAWS,eAC1E7B,OAAQ,CAACS,WAIQ,UAAdN,EAAKC,MACdL,EAAOM,KAAK,CACVhB,KAAMc,EAAKG,SACXC,KAAMxB,EAAYoB,EAAK2B,aAOd,CACb/B,OAAAA,EACAC,OAAAA,EACAkB,QAASrB,OAAOC,OAAOG,ICjGR8B,CAAqBvC,EAAQJ,GAE5C4C,KAAKC,SAAS,CACZ7B,KAAM,QACNE,mBAAUlB,UAAA8C,EAAS5B,WAAY,qBAC/BwB,OAAQK,KAAKC,UAAU3C"}
@@ -1,12 +1,30 @@
1
1
  import path from 'node:path';
2
2
 
3
+ function _extends() {
4
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
5
+ for (var i = 1; i < arguments.length; i++) {
6
+ var source = arguments[i];
7
+ for (var key in source) {
8
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
9
+ target[key] = source[key];
10
+ }
11
+ }
12
+ }
13
+ return target;
14
+ };
15
+ return _extends.apply(this, arguments);
16
+ }
17
+
3
18
  var getByteSize = function getByteSize(content) {
4
19
  if (typeof content === 'string') {
5
20
  return Buffer.from(content).length;
6
21
  }
7
22
  return (content == null ? void 0 : content.length) || 0;
8
23
  };
9
- var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
24
+ var bundleToWebpackStats = function bundleToWebpackStats(bundle, customOptions) {
25
+ var options = _extends({
26
+ moduleOriginalSize: false
27
+ }, customOptions);
10
28
  var items = Object.values(bundle);
11
29
  var assets = [];
12
30
  var chunks = [];
@@ -21,7 +39,7 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
21
39
  chunks.push({
22
40
  id: chunkId,
23
41
  entry: item.isEntry,
24
- initial: item.isEntry,
42
+ initial: !item.isDynamicEntry,
25
43
  files: [item.fileName],
26
44
  names: [item.name]
27
45
  });
@@ -35,7 +53,7 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
35
53
  } else {
36
54
  moduleByFileName[relativeModulePath] = {
37
55
  name: relativeModulePath,
38
- size: moduleInfo.originalLength,
56
+ size: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength,
39
57
  chunks: [chunkId]
40
58
  };
41
59
  }
@@ -56,14 +74,18 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
56
74
  };
57
75
 
58
76
  var NAME = 'webpackStats';
59
- var webpackStats = function webpackStats() {
77
+ var webpackStats = function webpackStats(options) {
78
+ if (options === void 0) {
79
+ options = {};
80
+ }
60
81
  return {
61
82
  name: NAME,
62
83
  generateBundle: function generateBundle(_, bundle) {
63
- var output = bundleToWebpackStats(bundle);
84
+ var _options;
85
+ var output = bundleToWebpackStats(bundle, options);
64
86
  this.emitFile({
65
87
  type: 'asset',
66
- fileName: 'webpack-stats.json',
88
+ fileName: ((_options = options) == null ? void 0 : _options.fileName) || 'webpack-stats.json',
67
89
  source: JSON.stringify(output)
68
90
  });
69
91
  }
@@ -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\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,CAAC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Q,EAAE,oBAAoB;QAC9BsB,MAAM,EAAEO,IAAI,CAACC,SAAS,CAACP,MAAM;OAC9B,CAAC;;GAEL;AAAA,CAAC;;;;"}
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 type BundleTransformOptions = {\n /**\n * Extract module original size or rendered size\n * default: false\n */\n moduleOriginalSize?: boolean;\n};\n\nexport const bundleToWebpackStats = (bundle: OutputBundle, customOptions?: BundleTransformOptions): WebpackStatsFiltered => {\n const options = {\n moduleOriginalSize: false,\n ...customOptions,\n };\n\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.isDynamicEntry,\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: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength,\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 { BundleTransformOptions, bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\ninterface WebpackStatsOptions extends BundleTransformOptions {\n /**\n * JSON file output fileName\n * default: webpack-stats.json\n */\n fileName?: string;\n}\n\nexport const webpackStats = (options: WebpackStatsOptions = {}): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle, options);\n\n this.emitFile({\n type: 'asset',\n fileName: options?.fileName || 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n"],"names":["getByteSize","content","Buffer","from","length","bundleToWebpackStats","bundle","customOptions","options","moduleOriginalSize","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","name","fileName","size","code","chunkId","id","entry","isEntry","initial","isDynamicEntry","files","names","entries","modules","modulePath","moduleInfo","relativeModulePath","path","relative","process","cwd","replace","moduleEntry","originalLength","renderedLength","source","output","NAME","webpackStats","generateBundle","_","emitFile","JSON","stringify"],"mappings":";;;;;;;;;;;;;;;;;AAwCA,IAAMA,WAAW,GAAG,SAAdA,WAAW,CAAIC,O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CAAC;;;;"}
@@ -29,4 +29,11 @@ export interface WebpackStatsFiltered {
29
29
  chunks?: Array<WebpackStatsFilteredChunk>;
30
30
  modules?: Array<WebpackStatsFilteredRootModule>;
31
31
  }
32
- export declare const bundleToWebpackStats: (bundle: OutputBundle) => WebpackStatsFiltered;
32
+ export declare type BundleTransformOptions = {
33
+ /**
34
+ * Extract module original size or rendered size
35
+ * default: false
36
+ */
37
+ moduleOriginalSize?: boolean;
38
+ };
39
+ export declare const bundleToWebpackStats: (bundle: OutputBundle, customOptions?: BundleTransformOptions | undefined) => WebpackStatsFiltered;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup-plugin-webpack-stats",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1,17 +1,25 @@
1
1
  import { Plugin } from 'rollup';
2
2
 
3
- import { bundleToWebpackStats } from './transform';
3
+ import { BundleTransformOptions, bundleToWebpackStats } from './transform';
4
4
 
5
5
  const NAME = 'webpackStats';
6
6
 
7
- export const webpackStats = (): Plugin => ({
7
+ interface WebpackStatsOptions extends BundleTransformOptions {
8
+ /**
9
+ * JSON file output fileName
10
+ * default: webpack-stats.json
11
+ */
12
+ fileName?: string;
13
+ }
14
+
15
+ export const webpackStats = (options: WebpackStatsOptions = {}): Plugin => ({
8
16
  name: NAME,
9
17
  generateBundle(_, bundle) {
10
- const output = bundleToWebpackStats(bundle);
18
+ const output = bundleToWebpackStats(bundle, options);
11
19
 
12
20
  this.emitFile({
13
21
  type: 'asset',
14
- fileName: 'webpack-stats.json',
22
+ fileName: options?.fileName || 'webpack-stats.json',
15
23
  source: JSON.stringify(output),
16
24
  });
17
25
  },
package/src/transform.ts CHANGED
@@ -46,7 +46,20 @@ const getByteSize = (content: string | Buffer): number => {
46
46
  return content?.length || 0;
47
47
  };
48
48
 
49
- export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {
49
+ export type BundleTransformOptions = {
50
+ /**
51
+ * Extract module original size or rendered size
52
+ * default: false
53
+ */
54
+ moduleOriginalSize?: boolean;
55
+ };
56
+
57
+ export const bundleToWebpackStats = (bundle: OutputBundle, customOptions?: BundleTransformOptions): WebpackStatsFiltered => {
58
+ const options = {
59
+ moduleOriginalSize: false,
60
+ ...customOptions,
61
+ };
62
+
50
63
  const items = Object.values(bundle);
51
64
 
52
65
  const assets: Array<WebpackStatsFilteredAsset> = [];
@@ -66,9 +79,9 @@ export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered
66
79
  chunks.push({
67
80
  id: chunkId,
68
81
  entry: item.isEntry,
69
- initial: item.isEntry,
82
+ initial: !item.isDynamicEntry,
70
83
  files: [item.fileName],
71
- names: [item.name]
84
+ names: [item.name],
72
85
  });
73
86
 
74
87
  Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {
@@ -81,7 +94,7 @@ export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered
81
94
  } else {
82
95
  moduleByFileName[relativeModulePath] = {
83
96
  name: relativeModulePath,
84
- size: moduleInfo.originalLength,
97
+ size: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength,
85
98
  chunks: [chunkId],
86
99
  };
87
100
  }