rollup-plugin-webpack-stats 0.0.3 → 0.0.4

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 CHANGED
@@ -1,14 +1,15 @@
1
1
  # rollup-plugin-webpack-stats
2
2
 
3
3
  > **Warning**
4
- Under active development
5
-
4
+ > Under active development
5
+
6
6
  [![](https://img.shields.io/npm/v/rollup-plugin-webpack-stats.svg)](https://www.npmjs.com/package/rollup-plugin-webpack-stats)
7
7
  ![](https://img.shields.io/node/v/rollup-plugin-webpack-stats.svg)
8
+ [![CI](https://github.com/vio/rollup-plugin-webpack-stats/actions/workflows/main.yml/badge.svg)](https://github.com/vio/rollup-plugin-webpack-stats/actions/workflows/main.yml)
8
9
 
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).
10
+ Generate rollup stats JSON file with a [bundle-stats](https://github.com/relative-ci/bundle-stats/tree/master/packages/cli) webpack [supported structure](https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts).
10
11
 
11
- ## Install
12
+ ## Install
12
13
 
13
14
  ```shell
14
15
  npm install --dev rollup-plugin-webpack-stats
@@ -22,7 +23,6 @@ yarn add --dev rollup-plugin-webpack-stats
22
23
 
23
24
  ## Configure
24
25
 
25
-
26
26
  ```js
27
27
  // rollup.config.js
28
28
  const { webpackStats } = require('rollup-plugin-webpack-stats');
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
- var path = _interopDefault(require('node:path'));
7
+ var path = _interopDefault(require('path'));
8
8
 
9
9
  function _extends() {
10
10
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -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 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,CAACF,OAAO,CAAC,CAACG,MAAM;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WAAW,CAAC5B,MAAM,CAACK,IAAI,CAACK,OAAO,CAAC;SACjC,MAAM;UACLT,gBAAgB,CAACqB,kBAAkB,CAAC,GAAG;YACrChB,IAAI,EAAEgB,kBAAkB;YACxBd,IAAI,EAAEd,OAAO,CAACC,kBAAkB,GAAG0B,UAAU,CAACQ,cAAc,GAAGR,UAAU,CAACS,cAAc;YACxF9B,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,EAAEtB,WAAW,CAACiB,IAAI,CAAC4B,MAAM;OAC9B,CAAC;;GAIL,CAAC;EAEF,IAAMC,MAAM,GAAG;IACbjC,MAAM,EAANA,MAAM;IACNC,MAAM,EAANA,MAAM;IACNmB,OAAO,EAAEtB,MAAM,CAACC,MAAM,CAACG,gBAAgB;GACxC;EAED,OAAO+B,MAAM;AACf,CAAC;;AClHD,IAAMC,IAAI,GAAG,cAAc;AAU3B,IAAaC,YAAY,GAAG,SAAfA,YAAY,CAAIxC;MAAAA;IAAAA,UAA+B,EAAE;;EAAA,OAAc;IAC1EY,IAAI,EAAE2B,IAAI;IACVE,cAAc,0BAACC,CAAC,EAAE5C,MAAM;;MACtB,IAAMwC,MAAM,GAAGzC,oBAAoB,CAACC,MAAM,EAAEE,OAAO,CAAC;MAEpD,IAAI,CAAC2C,QAAQ,CAAC;QACZjC,IAAI,EAAE,OAAO;QACbG,QAAQ,EAAE,aAAAb,OAAO,qBAAP,SAASa,QAAQ,KAAI,oBAAoB;QACnDwB,MAAM,EAAEO,IAAI,CAACC,SAAS,CAACP,MAAM;OAC9B,CAAC;;GAEL;AAAA,CAAC;;;;"}
1
+ {"version":3,"file":"rollup-plugin-webpack-stats.cjs.development.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from '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\n 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 = (\n bundle: OutputBundle,\n customOptions?: BundleTransformOptions\n): 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(\n process.cwd(),\n modulePath.replace('\\u0000', '')\n );\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\n ? moduleInfo.originalLength\n : 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":";;;;;;;;;;;;;;;;;;;;;;;AAyCA,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;A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gBAAgB,CAACqB,kBAAkB,CAAC,GAAG;YACrChB,IAAI,EAAEgB,kBAAkB;YACxBd,IAAI,EAAEd,OAAO,CAACC,kBAAkB,GAC5B0B,UAAU,CAACQ,cAAc,GACzBR,UAAU,CAACS,cAAc;YAC7B9B,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,EAAEtB,WAAW,CAACiB,IAAI,CAAC4B,MAAM;OAC9B,CAAC;;GAIL,CAAC;EAEF,IAAMC,MAAM,GAAG;IACbjC,MAAM,EAANA,MAAM;IACNC,MAAM,EAANA,MAAM;IACNmB,OAAO,EAAEtB,MAAM,CAACC,MAAM,CAACG,gBAAgB;GACxC;EAED,OAAO+B,MAAM;AACf,CAAC;;AC3HD,IAAMC,IAAI,GAAG,cAAc;AAU3B,IAAaC,YAAY,GAAG,SAAfA,YAAY,CAAIxC;MAAAA;IAAAA,UAA+B,EAAE;;EAAA,OAAc;IAC1EY,IAAI,EAAE2B,IAAI;IACVE,cAAc,0BAACC,CAAC,EAAE5C,MAAM;;MACtB,IAAMwC,MAAM,GAAGzC,oBAAoB,CAACC,MAAM,EAAEE,OAAO,CAAC;MAEpD,IAAI,CAAC2C,QAAQ,CAAC;QACZjC,IAAI,EAAE,OAAO;QACbG,QAAQ,EAAE,aAAAb,OAAO,qBAAP,SAASa,QAAQ,KAAI,oBAAoB;QACnDwB,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;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)})}}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("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 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
+ {"version":3,"file":"rollup-plugin-webpack-stats.cjs.production.min.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from '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\n 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 = (\n bundle: OutputBundle,\n customOptions?: BundleTransformOptions\n): 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(\n process.cwd(),\n modulePath.replace('\\u0000', '')\n );\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\n ? moduleInfo.originalLength\n : 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":"kXAyCA,IAAMA,EAAc,SAACC,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path';
1
+ import path from 'path';
2
2
 
3
3
  function _extends() {
4
4
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -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 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,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"version":3,"file":"rollup-plugin-webpack-stats.esm.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from '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\n 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 = (\n bundle: OutputBundle,\n customOptions?: BundleTransformOptions\n): 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(\n process.cwd(),\n modulePath.replace('\\u0000', '')\n );\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\n ? moduleInfo.originalLength\n : 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":";;;;;;;;;;;;;;;;;AAyCA,IAAMA,WAAW,GAAG,SAAdA,WAAW,CAAIC,OAAwB;EAC3C,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;IAC/B,OAAOC,MAAM,CAACC,IAAI,CAACF,OAAO,CA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0.3",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
package/src/transform.ts CHANGED
@@ -1,11 +1,11 @@
1
- import path from 'node:path';
1
+ import path from 'path';
2
2
  import { OutputBundle } from 'rollup';
3
3
 
4
4
  // https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts
5
5
  export type WebpackStatsFilteredAsset = {
6
6
  name: string;
7
7
  size?: number;
8
- }
8
+ };
9
9
 
10
10
  export interface WebpackStatsFilteredChunk {
11
11
  id: number | string;
@@ -26,7 +26,8 @@ export interface WebpackStatsFilteredConcatenatedModule {
26
26
  size?: number;
27
27
  }
28
28
 
29
- export interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {
29
+ export interface WebpackStatsFilteredRootModule
30
+ extends WebpackStatsFilteredModule {
30
31
  modules?: Array<WebpackStatsFilteredConcatenatedModule>;
31
32
  }
32
33
 
@@ -54,7 +55,10 @@ export type BundleTransformOptions = {
54
55
  moduleOriginalSize?: boolean;
55
56
  };
56
57
 
57
- export const bundleToWebpackStats = (bundle: OutputBundle, customOptions?: BundleTransformOptions): WebpackStatsFiltered => {
58
+ export const bundleToWebpackStats = (
59
+ bundle: OutputBundle,
60
+ customOptions?: BundleTransformOptions
61
+ ): WebpackStatsFiltered => {
58
62
  const options = {
59
63
  moduleOriginalSize: false,
60
64
  ...customOptions,
@@ -67,7 +71,7 @@ export const bundleToWebpackStats = (bundle: OutputBundle, customOptions?: Bundl
67
71
 
68
72
  const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};
69
73
 
70
- items.forEach((item) => {
74
+ items.forEach(item => {
71
75
  if (item.type === 'chunk') {
72
76
  assets.push({
73
77
  name: item.fileName,
@@ -85,7 +89,10 @@ export const bundleToWebpackStats = (bundle: OutputBundle, customOptions?: Bundl
85
89
  });
86
90
 
87
91
  Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {
88
- const relativeModulePath = path.relative(process.cwd(), modulePath.replace('\u0000', ''));
92
+ const relativeModulePath = path.relative(
93
+ process.cwd(),
94
+ modulePath.replace('\u0000', '')
95
+ );
89
96
 
90
97
  const moduleEntry = moduleByFileName[relativeModulePath];
91
98
 
@@ -94,7 +101,9 @@ export const bundleToWebpackStats = (bundle: OutputBundle, customOptions?: Bundl
94
101
  } else {
95
102
  moduleByFileName[relativeModulePath] = {
96
103
  name: relativeModulePath,
97
- size: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength,
104
+ size: options.moduleOriginalSize
105
+ ? moduleInfo.originalLength
106
+ : moduleInfo.renderedLength,
98
107
  chunks: [chunkId],
99
108
  };
100
109
  }