rollup-plugin-webpack-stats 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Plugin } from 'rollup';
2
2
  import { BundleTransformOptions } from './transform';
3
+ export { bundleToWebpackStats } from './transform';
3
4
  interface WebpackStatsOptions extends BundleTransformOptions {
4
5
  /**
5
6
  * JSON file output fileName
@@ -8,4 +9,3 @@ interface WebpackStatsOptions extends BundleTransformOptions {
8
9
  fileName?: string;
9
10
  }
10
11
  export declare const webpackStats: (options?: WebpackStatsOptions) => Plugin;
11
- export {};
@@ -71,7 +71,7 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle, customOptions)
71
71
  } else if (item.type === 'asset') {
72
72
  assets.push({
73
73
  name: item.fileName,
74
- size: getByteSize(item.source)
74
+ size: getByteSize(item.source.toString())
75
75
  });
76
76
  }
77
77
  });
@@ -102,5 +102,6 @@ var webpackStats = function webpackStats(options) {
102
102
  };
103
103
  };
104
104
 
105
+ exports.bundleToWebpackStats = bundleToWebpackStats;
105
106
  exports.webpackStats = webpackStats;
106
107
  //# sourceMappingURL=rollup-plugin-webpack-stats.cjs.development.js.map
@@ -1 +1 @@
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 // Remove unexpected rollup null prefix\n const normalizedModulePath = modulePath.replace('\\u0000', '');\n\n const relativeModulePath = path.relative(\n process.cwd(),\n normalizedModulePath\n );\n\n // Match webpack output - add current directory prefix for child modules\n const relativeModulePathWithPrefix = relativeModulePath.match(/^\\.\\./)\n ? relativeModulePath\n : `.${path.sep}${relativeModulePath}`;\n\n const moduleEntry = moduleByFileName[relativeModulePathWithPrefix];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePathWithPrefix] = {\n name: relativeModulePathWithPrefix,\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 return {\n builtAt: Date.now(),\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\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","normalizedModulePath","replace","relativeModulePath","path","relative","process","cwd","relativeModulePathWithPrefix","match","sep","moduleEntry","originalLength","renderedLength","source","builtAt","Date","now","NAME","webpackStats","generateBundle","_","output","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;AAC7B,CAAC;AAUM,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAoB,CAC/BC,MAAoB,EACpBC,aAAsC;EAEtC,IAAMC,O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AW,CAAChC,MAAM,CAACK,IAAI,CAACK,OAAO,CAAC;SACjC,MAAM;UACLT,gBAAgB,CAAC4B,4BAA4B,CAAC,GAAG;YAC/CvB,IAAI,EAAEuB,4BAA4B;YAClCrB,IAAI,EAAEd,OAAO,CAACC,kBAAkB,GAC5B0B,UAAU,CAACY,cAAc,GACzBZ,UAAU,CAACa,cAAc;YAC7BlC,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,CAACgC,MAAM;OAC9B,CAAC;;GAIL,CAAC;EAEF,OAAO;IACLC,OAAO,EAAEC,IAAI,CAACC,GAAG,EAAE;IACnBvC,MAAM,EAANA,MAAM;IACNC,MAAM,EAANA,MAAM;IACNmB,OAAO,EAAEtB,MAAM,CAACC,MAAM,CAACG,gBAAgB;GACxC;AACH,CAAC;;AClID,IAAMsC,IAAI,GAAG,cAAc;AAU3B,IAAaC,YAAY,GAAG,SAAfA,YAAY,CAAI9C;MAAAA;IAAAA,UAA+B,EAAE;;EAAA,OAAc;IAC1EY,IAAI,EAAEiC,IAAI;IACVE,cAAc,0BAACC,CAAC,EAAElD,MAAM;;MACtB,IAAMmD,MAAM,GAAGpD,oBAAoB,CAACC,MAAM,EAAEE,OAAO,CAAC;MAEpD,IAAI,CAACkD,QAAQ,CAAC;QACZxC,IAAI,EAAE,OAAO;QACbG,QAAQ,EAAE,aAAAb,OAAO,qBAAP,SAASa,QAAQ,KAAI,oBAAoB;QACnD4B,MAAM,EAAEU,IAAI,CAACC,SAAS,CAACH,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 // Remove unexpected rollup null prefix\n const normalizedModulePath = modulePath.replace('\\u0000', '');\n\n const relativeModulePath = path.relative(\n process.cwd(),\n normalizedModulePath\n );\n\n // Match webpack output - add current directory prefix for child modules\n const relativeModulePathWithPrefix = relativeModulePath.match(/^\\.\\./)\n ? relativeModulePath\n : `.${path.sep}${relativeModulePath}`;\n\n const moduleEntry = moduleByFileName[relativeModulePathWithPrefix];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePathWithPrefix] = {\n name: relativeModulePathWithPrefix,\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.toString()),\n });\n } else {\n // noop for unknown types\n }\n });\n\n return {\n builtAt: Date.now(),\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n};\n","import { Plugin } from 'rollup';\n\nimport { BundleTransformOptions, bundleToWebpackStats } from './transform';\n\nexport { 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","normalizedModulePath","replace","relativeModulePath","path","relative","process","cwd","relativeModulePathWithPrefix","match","sep","moduleEntry","originalLength","renderedLength","source","toString","builtAt","Date","now","NAME","webpackStats","generateBundle","_","output","emitF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AEnD,MAAM;;MACtB,IAAMoD,MAAM,GAAGrD,oBAAoB,CAACC,MAAM,EAAEE,OAAO,CAAC;MAEpD,IAAI,CAACmD,QAAQ,CAAC;QACZzC,IAAI,EAAE,OAAO;QACbG,QAAQ,EAAE,aAAAb,OAAO,qBAAP,SAASa,QAAQ,KAAI,oBAAoB;QACnD4B,MAAM,EAAEW,IAAI,CAACC,SAAS,CAACH,MAAM;OAC9B,CAAC;;GAEL;AAAA,CAAC;;;;;"}
@@ -1,2 +1,2 @@
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(a,r){var s,u=function(e,a){var r=n({moduleOriginalSize:!1},a),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[1],a=e[0].replace("\0",""),s=t.relative(process.cwd(),a),u=s.match(/^\.\./)?s:"."+t.sep+s,o=l[u];o?o.chunks.push(n):l[u]={name:u,size:r.moduleOriginalSize?i.originalLength:i.renderedLength,chunks:[n]}}))}else"asset"===e.type&&u.push({name:e.fileName,size:i(e.source)})})),{builtAt:Date.now(),assets:u,chunks:o,modules:Object.values(l)}}(r,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 a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}var a=function(e){return"string"==typeof e?Buffer.from(e).length:(null==e?void 0:e.length)||0},i=function(e,i){var r=n({moduleOriginalSize:!1},i),s=Object.values(e),u=[],o=[],l={};return s.forEach((function(e){if("chunk"===e.type){u.push({name:e.fileName,size:a(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 a=e[1],i=e[0].replace("\0",""),s=t.relative(process.cwd(),i),u=s.match(/^\.\./)?s:"."+t.sep+s,o=l[u];o?o.chunks.push(n):l[u]={name:u,size:r.moduleOriginalSize?a.originalLength:a.renderedLength,chunks:[n]}}))}else"asset"===e.type&&u.push({name:e.fileName,size:a(e.source.toString())})})),{builtAt:Date.now(),assets:u,chunks:o,modules:Object.values(l)}};exports.bundleToWebpackStats=i,exports.webpackStats=function(e){return void 0===e&&(e={}),{name:"webpackStats",generateBundle:function(t,n){var a,r=i(n,e);this.emitFile({type:"asset",fileName:(null==(a=e)?void 0:a.fileName)||"webpack-stats.json",source:JSON.stringify(r)})}}};
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 '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 // Remove unexpected rollup null prefix\n const normalizedModulePath = modulePath.replace('\\u0000', '');\n\n const relativeModulePath = path.relative(\n process.cwd(),\n normalizedModulePath\n );\n\n // Match webpack output - add current directory prefix for child modules\n const relativeModulePathWithPrefix = relativeModulePath.match(/^\\.\\./)\n ? relativeModulePath\n : `.${path.sep}${relativeModulePath}`;\n\n const moduleEntry = moduleByFileName[relativeModulePathWithPrefix];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePathWithPrefix] = {\n name: relativeModulePathWithPrefix,\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 return {\n builtAt: Date.now(),\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\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","moduleInfo","normalizedModulePath","replace","relativeModulePath","path","relative","process","cwd","relativeModulePathWithPrefix","match","sep","moduleEntry","originalLength","renderedLength","source","builtAt","Date","now","bundleToWebpackStats","this","emitFile","_options","JSON","stringify"],"mappings":"kXAyCA,IAAMA,EAAc,SAACC,GACnB,MAAuB,iBAAZA,EACFC,OAAOC,KAAKF,GAASG,cAGvBH,SAAAA,EAASG,SAAU,wBChCA,SAACC,GAAiC,gBAAjCA,IAAAA,EAA+B,IAAgB,CAC1EC,KAXW,eAYXC,wBAAeC,EAAGC,SACVC,EDwC0B,SAClCD,EACAE,GAEA,IAAMN,KACJO,oBAAoB,GACjBD,GAGCE,EAAQC,OAAOC,OAAON,GAEtBO,EAA2C,GAC3CC,EAA2C,GAE3CC,EAA+D,GAyDrE,OAvDAL,EAAMM,SAAQ,SAAAC,GACZ,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,gBAAciB,OAE3CC,OAAkCC,QAAQ,KAAU,IAEpDC,EAAqBC,EAAKC,SAC9BC,QAAQC,MACRN,GAIIO,EAA+BL,EAAmBM,MAAM,SAC1DN,MACIC,EAAKM,IAAMP,EAEbQ,EAAc7B,EAAiB0B,GAEjCG,EACFA,EAAY9B,OAAOK,KAAKI,GAExBR,EAAiB0B,GAAgC,CAC/CtC,KAAMsC,EACNpB,KAAMnB,EAAQO,mBACVwB,EAAWY,eACXZ,EAAWa,eACfhC,OAAQ,CAACS,WAIQ,UAAdN,EAAKC,MACdL,EAAOM,KAAK,CACVhB,KAAMc,EAAKG,SACXC,KAAMxB,EAAYoB,EAAK8B,aAOtB,CACLC,QAASC,KAAKC,MACdrC,OAAAA,EACAC,OAAAA,EACAkB,QAASrB,OAAOC,OAAOG,ICnHRoC,CAAqB7C,EAAQJ,GAE5CkD,KAAKC,SAAS,CACZnC,KAAM,QACNE,mBAAUlB,UAAAoD,EAASlC,WAAY,qBAC/B2B,OAAQQ,KAAKC,UAAUjD"}
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 // Remove unexpected rollup null prefix\n const normalizedModulePath = modulePath.replace('\\u0000', '');\n\n const relativeModulePath = path.relative(\n process.cwd(),\n normalizedModulePath\n );\n\n // Match webpack output - add current directory prefix for child modules\n const relativeModulePathWithPrefix = relativeModulePath.match(/^\\.\\./)\n ? relativeModulePath\n : `.${path.sep}${relativeModulePath}`;\n\n const moduleEntry = moduleByFileName[relativeModulePathWithPrefix];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePathWithPrefix] = {\n name: relativeModulePathWithPrefix,\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.toString()),\n });\n } else {\n // noop for unknown types\n }\n });\n\n return {\n builtAt: Date.now(),\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n};\n","import { Plugin } from 'rollup';\n\nimport { BundleTransformOptions, bundleToWebpackStats } from './transform';\n\nexport { 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","moduleInfo","normalizedModulePath","replace","relativeModulePath","path","relative","process","cwd","relativeModulePathWithPrefix","match","sep","moduleEntry","originalLength","renderedLength","source","toString","builtAt","Date","now","generateBundle","_","output","this","emitFile","_options","JSON","stringify"],"mappings":"kXAyCA,IAAMA,EAAc,SAACC,GACnB,MAAuB,iBAAZA,EACFC,OAAOC,KAAKF,GAASG,cAGvBH,SAAAA,EAASG,S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7 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle, customOptions)
65
65
  } else if (item.type === 'asset') {
66
66
  assets.push({
67
67
  name: item.fileName,
68
- size: getByteSize(item.source)
68
+ size: getByteSize(item.source.toString())
69
69
  });
70
70
  }
71
71
  });
@@ -96,5 +96,5 @@ var webpackStats = function webpackStats(options) {
96
96
  };
97
97
  };
98
98
 
99
- export { webpackStats };
99
+ export { bundleToWebpackStats, webpackStats };
100
100
  //# sourceMappingURL=rollup-plugin-webpack-stats.esm.js.map
@@ -1 +1 @@
1
- {"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 // Remove unexpected rollup null prefix\n const normalizedModulePath = modulePath.replace('\\u0000', '');\n\n const relativeModulePath = path.relative(\n process.cwd(),\n normalizedModulePath\n );\n\n // Match webpack output - add current directory prefix for child modules\n const relativeModulePathWithPrefix = relativeModulePath.match(/^\\.\\./)\n ? relativeModulePath\n : `.${path.sep}${relativeModulePath}`;\n\n const moduleEntry = moduleByFileName[relativeModulePathWithPrefix];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePathWithPrefix] = {\n name: relativeModulePathWithPrefix,\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 return {\n builtAt: Date.now(),\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\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","normalizedModulePath","replace","relativeModulePath","path","relative","process","cwd","relativeModulePathWithPrefix","match","sep","moduleEntry","originalLength","renderedLength","source","builtAt","Date","now","NAME","webpackStats","generateBundle","_","output","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;AAC7B,CAAC;AAUM,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAoB,CAC/BC,MAAoB,EACpBC,aAAsC;EAEtC,IAAMC,OAAO;IACXC,kBAAkB,EAAE;KACjBF,aAAa,CACjB;EAED,IAAMG,KAAK,GAAGC,MAAM,CAACC,MAAM,CAACN,MAAM,CAAC;EAEnC,IAAMO,MAAM,GAAqC,EAAE;EACnD,IAAMC,MAAM,GAAqC,EAAE;EAEnD,IAAMC,gBAAgB,GAA+C,EAAE;EAEvEL,KAAK,CAACM,OAAO,CAAC,UAAAC,IAAI;IAChB,IAAIA,IAAI,CAACC,IAAI,KAAK,OAAO,EAAE;MACzBL,MAAM,CAACM,IAAI,CAAC;QACVC,IAAI,EAAEH,IAAI,CAACI,QAAQ;QACnBC,IAAI,EAAEtB,WAAW,CAACiB,IAAI,CAACM,IAAI;OAC5B,CAAC;MAEF,IAAMC,OAAO,GAAGP,IAAI,C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AC;;GAIL,CAAC;EAEF,OAAO;IACLC,OAAO,EAAEC,IAAI,CAACC,GAAG,EAAE;IACnBvC,MAAM,EAANA,MAAM;IACNC,MAAM,EAANA,MAAM;IACNmB,OAAO,EAAEtB,MAAM,CAACC,MAAM,CAACG,gBAAgB;GACxC;AACH,CAAC;;AClID,IAAMsC,IAAI,GAAG,cAAc;AAU3B,IAAaC,YAAY,GAAG,SAAfA,YAAY,CAAI9C;MAAAA;IAAAA,UAA+B,EAAE;;EAAA,OAAc;IAC1EY,IAAI,EAAEiC,IAAI;IACVE,cAAc,0BAACC,CAAC,EAAElD,MAAM;;MACtB,IAAMmD,MAAM,GAAGpD,oBAAoB,CAACC,MAAM,EAAEE,OAAO,CAAC;MAEpD,IAAI,CAACkD,QAAQ,CAAC;QACZxC,IAAI,EAAE,OAAO;QACbG,QAAQ,EAAE,aAAAb,OAAO,qBAAP,SAASa,QAAQ,KAAI,oBAAoB;QACnD4B,MAAM,EAAEU,IAAI,CAACC,SAAS,CAACH,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 '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 // Remove unexpected rollup null prefix\n const normalizedModulePath = modulePath.replace('\\u0000', '');\n\n const relativeModulePath = path.relative(\n process.cwd(),\n normalizedModulePath\n );\n\n // Match webpack output - add current directory prefix for child modules\n const relativeModulePathWithPrefix = relativeModulePath.match(/^\\.\\./)\n ? relativeModulePath\n : `.${path.sep}${relativeModulePath}`;\n\n const moduleEntry = moduleByFileName[relativeModulePathWithPrefix];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePathWithPrefix] = {\n name: relativeModulePathWithPrefix,\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.toString()),\n });\n } else {\n // noop for unknown types\n }\n });\n\n return {\n builtAt: Date.now(),\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n};\n","import { Plugin } from 'rollup';\n\nimport { BundleTransformOptions, bundleToWebpackStats } from './transform';\n\nexport { 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","normalizedModulePath","replace","relativeModulePath","path","relative","process","cwd","relativeModulePathWithPrefix","match","sep","moduleEntry","originalLength","renderedLength","source","toString","builtAt","Date","now","NAME","webpackStats","generateBundle","_","output","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;AAC7B,CAAC;IAUYC,oBAAoB,GAAG,SAAvBA,oBAAoB,CAC/BC,MAAoB,EACpBC,aAAsC;EAEtC,IAAMC,OAAO;IACXC,kBAAkB,EAAE;KACjBF,aAAa,CACjB;EAED,IAAMG,KAAK,GAAGC,MAAM,CAACC,MAAM,CAACN,MAAM,CAAC;EAE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B,IAAI,EAAEuB,4BAA4B;YAClCrB,IAAI,EAAEd,OAAO,CAACC,kBAAkB,GAC5B0B,UAAU,CAACY,cAAc,GACzBZ,UAAU,CAACa,cAAc;YAC7BlC,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,CAACgC,MAAM,CAACC,QAAQ,EAAE;OACzC,CAAC;;GAIL,CAAC;EAEF,OAAO;IACLC,OAAO,EAAEC,IAAI,CAACC,GAAG,EAAE;IACnBxC,MAAM,EAANA,MAAM;IACNC,MAAM,EAANA,MAAM;IACNmB,OAAO,EAAEtB,MAAM,CAACC,MAAM,CAACG,gBAAgB;GACxC;AACH;;AChIA,IAAMuC,IAAI,GAAG,cAAc;AAU3B,IAAaC,YAAY,GAAG,SAAfA,YAAY,CAAI/C;MAAAA;IAAAA,UAA+B,EAAE;;EAAA,OAAc;IAC1EY,IAAI,EAAEkC,IAAI;IACVE,cAAc,0BAACC,CAAC,EAAEnD,MAAM;;MACtB,IAAMoD,MAAM,GAAGrD,oBAAoB,CAACC,MAAM,EAAEE,OAAO,CAAC;MAEpD,IAAI,CAACmD,QAAQ,CAAC;QACZzC,IAAI,EAAE,OAAO;QACbG,QAAQ,EAAE,aAAAb,OAAO,qBAAP,SAASa,QAAQ,KAAI,oBAAoB;QACnD4B,MAAM,EAAEW,IAAI,CAACC,SAAS,CAACH,MAAM;OAC9B,CAAC;;GAEL;AAAA,CAAC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup-plugin-webpack-stats",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -47,13 +47,13 @@
47
47
  "module": "dist/rollup-plugin-webpack-stats.esm.js",
48
48
  "devDependencies": {
49
49
  "husky": "^8.0.3",
50
- "rollup": "^1.32.1",
50
+ "rollup": "^3.10.0",
51
51
  "size-limit": "^8.1.1",
52
52
  "tsdx": "^0.14.1",
53
53
  "tslib": "^2.4.1",
54
54
  "typescript": "^4.9.4"
55
55
  },
56
56
  "peerDependencies": {
57
- "rollup": "^1.0.0"
57
+ "rollup": "^3.0.0"
58
58
  }
59
59
  }
package/src/index.ts CHANGED
@@ -2,6 +2,8 @@ import { Plugin } from 'rollup';
2
2
 
3
3
  import { BundleTransformOptions, bundleToWebpackStats } from './transform';
4
4
 
5
+ export { bundleToWebpackStats } from './transform';
6
+
5
7
  const NAME = 'webpackStats';
6
8
 
7
9
  interface WebpackStatsOptions extends BundleTransformOptions {
package/src/transform.ts CHANGED
@@ -119,7 +119,7 @@ export const bundleToWebpackStats = (
119
119
  } else if (item.type === 'asset') {
120
120
  assets.push({
121
121
  name: item.fileName,
122
- size: getByteSize(item.source),
122
+ size: getByteSize(item.source.toString()),
123
123
  });
124
124
  } else {
125
125
  // noop for unknown types