rollup-plugin-webpack-stats 0.0.4 → 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/README.md +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/rollup-plugin-webpack-stats.cjs.development.js +12 -7
- package/dist/rollup-plugin-webpack-stats.cjs.development.js.map +1 -1
- package/dist/rollup-plugin-webpack-stats.cjs.production.min.js +1 -1
- package/dist/rollup-plugin-webpack-stats.cjs.production.min.js.map +1 -1
- package/dist/rollup-plugin-webpack-stats.esm.js +12 -8
- package/dist/rollup-plugin-webpack-stats.esm.js.map +1 -1
- package/package.json +18 -5
- package/src/index.ts +2 -0
- package/src/transform.ts +15 -8
package/README.md
CHANGED
|
@@ -34,3 +34,8 @@ module.exports = {
|
|
|
34
34
|
],
|
|
35
35
|
};
|
|
36
36
|
```
|
|
37
|
+
|
|
38
|
+
## Example setup with [@relative-ci/agent](https://github.com/relative-ci/agent)
|
|
39
|
+
|
|
40
|
+
- [example-vite-github-action](https://github.com/relative-ci/example-vite-github-action)
|
|
41
|
+
- [example-vite-cli-github-action](https://github.com/relative-ci/example-vite-cli-github-action)
|
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 {};
|
|
@@ -52,13 +52,17 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle, customOptions)
|
|
|
52
52
|
Object.entries(item.modules).forEach(function (_ref) {
|
|
53
53
|
var modulePath = _ref[0],
|
|
54
54
|
moduleInfo = _ref[1];
|
|
55
|
-
|
|
56
|
-
var
|
|
55
|
+
// Remove unexpected rollup null prefix
|
|
56
|
+
var normalizedModulePath = modulePath.replace("\0", '');
|
|
57
|
+
var relativeModulePath = path.relative(process.cwd(), normalizedModulePath);
|
|
58
|
+
// Match webpack output - add current directory prefix for child modules
|
|
59
|
+
var relativeModulePathWithPrefix = relativeModulePath.match(/^\.\./) ? relativeModulePath : "." + path.sep + relativeModulePath;
|
|
60
|
+
var moduleEntry = moduleByFileName[relativeModulePathWithPrefix];
|
|
57
61
|
if (moduleEntry) {
|
|
58
62
|
moduleEntry.chunks.push(chunkId);
|
|
59
63
|
} else {
|
|
60
|
-
moduleByFileName[
|
|
61
|
-
name:
|
|
64
|
+
moduleByFileName[relativeModulePathWithPrefix] = {
|
|
65
|
+
name: relativeModulePathWithPrefix,
|
|
62
66
|
size: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength,
|
|
63
67
|
chunks: [chunkId]
|
|
64
68
|
};
|
|
@@ -67,16 +71,16 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle, customOptions)
|
|
|
67
71
|
} else if (item.type === 'asset') {
|
|
68
72
|
assets.push({
|
|
69
73
|
name: item.fileName,
|
|
70
|
-
size: getByteSize(item.source)
|
|
74
|
+
size: getByteSize(item.source.toString())
|
|
71
75
|
});
|
|
72
76
|
}
|
|
73
77
|
});
|
|
74
|
-
|
|
78
|
+
return {
|
|
79
|
+
builtAt: Date.now(),
|
|
75
80
|
assets: assets,
|
|
76
81
|
chunks: chunks,
|
|
77
82
|
modules: Object.values(moduleByFileName)
|
|
78
83
|
};
|
|
79
|
-
return output;
|
|
80
84
|
};
|
|
81
85
|
|
|
82
86
|
var NAME = 'webpackStats';
|
|
@@ -98,5 +102,6 @@ var webpackStats = function webpackStats(options) {
|
|
|
98
102
|
};
|
|
99
103
|
};
|
|
100
104
|
|
|
105
|
+
exports.bundleToWebpackStats = bundleToWebpackStats;
|
|
101
106
|
exports.webpackStats = webpackStats;
|
|
102
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 const relativeModulePath = path.relative(\n process.cwd(),\n
|
|
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","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;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,CAACG,IAAI;MAEzBN,MAAM,CAACK,IAAI,CAAC;QACVM,EAAE,EAAED,OAAO;QAC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I,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;;;;;"}
|
|
@@ -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
|
|
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 const relativeModulePath = path.relative(\n process.cwd(),\n
|
|
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,SAAU,GAWfC,EAAuB,SAClCC,EACAC,GAEA,IAAMC,KACJC,oBAAoB,GACjBF,GAGCG,EAAQC,OAAOC,OAAON,GAEtBO,EAA2C,GAC3CC,EAA2C,GAE3CC,EAA+D,GAyDrE,OAvDAL,EAAMM,SAAQ,SAAAC,GACZ,GAAkB,UAAdA,EAAKC,KAAkB,CACzBL,EAAOM,KAAK,CACVC,KAAMH,EAAKI,SACXC,KAAMtB,EAAYiB,EAAKM,QAGzB,IAAMC,EAAUP,EAAKG,KAErBN,EAAOK,KAAK,CACVM,GAAID,EACJE,MAAOT,EAAKU,QACZC,SAAUX,EAAKY,eACfC,MAAO,CAACb,EAAKI,UACbU,MAAO,CAACd,EAAKG,QAGfT,OAAOqB,QAAQf,EAAKgB,SAASjB,SAAQ,gBAAckB,OAE3CC,OAAkCC,QAAQ,KAAU,IAEpDC,EAAqBC,EAAKC,SAC9BC,QAAQC,MACRN,GAIIO,EAA+BL,EAAmBM,MAAM,SAC1DN,MACIC,EAAKM,IAAMP,EAEbQ,EAAc9B,EAAiB2B,GAEjCG,EACFA,EAAY/B,OAAOK,KAAKK,GAExBT,EAAiB2B,GAAgC,CAC/CtB,KAAMsB,EACNpB,KAAMd,EAAQC,mBACVyB,EAAWY,eACXZ,EAAWa,eACfjC,OAAQ,CAACU,WAIQ,UAAdP,EAAKC,MACdL,EAAOM,KAAK,CACVC,KAAMH,EAAKI,SACXC,KAAMtB,EAAYiB,EAAK+B,OAAOC,iBAO7B,CACLC,QAASC,KAAKC,MACdvC,OAAAA,EACAC,OAAAA,EACAmB,QAAStB,OAAOC,OAAOG,yDCpHC,SAACP,GAAiC,gBAAjCA,IAAAA,EAA+B,IAAgB,CAC1EY,KAXW,eAYXiC,wBAAeC,EAAGhD,SACViD,EAASlD,EAAqBC,EAAQE,GAE5CgD,KAAKC,SAAS,CACZvC,KAAM,QACNG,mBAAUb,UAAAkD,EAASrC,WAAY,qBAC/B2B,OAAQW,KAAKC,UAAUL"}
|
|
@@ -46,13 +46,17 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle, customOptions)
|
|
|
46
46
|
Object.entries(item.modules).forEach(function (_ref) {
|
|
47
47
|
var modulePath = _ref[0],
|
|
48
48
|
moduleInfo = _ref[1];
|
|
49
|
-
|
|
50
|
-
var
|
|
49
|
+
// Remove unexpected rollup null prefix
|
|
50
|
+
var normalizedModulePath = modulePath.replace("\0", '');
|
|
51
|
+
var relativeModulePath = path.relative(process.cwd(), normalizedModulePath);
|
|
52
|
+
// Match webpack output - add current directory prefix for child modules
|
|
53
|
+
var relativeModulePathWithPrefix = relativeModulePath.match(/^\.\./) ? relativeModulePath : "." + path.sep + relativeModulePath;
|
|
54
|
+
var moduleEntry = moduleByFileName[relativeModulePathWithPrefix];
|
|
51
55
|
if (moduleEntry) {
|
|
52
56
|
moduleEntry.chunks.push(chunkId);
|
|
53
57
|
} else {
|
|
54
|
-
moduleByFileName[
|
|
55
|
-
name:
|
|
58
|
+
moduleByFileName[relativeModulePathWithPrefix] = {
|
|
59
|
+
name: relativeModulePathWithPrefix,
|
|
56
60
|
size: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength,
|
|
57
61
|
chunks: [chunkId]
|
|
58
62
|
};
|
|
@@ -61,16 +65,16 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle, customOptions)
|
|
|
61
65
|
} else if (item.type === 'asset') {
|
|
62
66
|
assets.push({
|
|
63
67
|
name: item.fileName,
|
|
64
|
-
size: getByteSize(item.source)
|
|
68
|
+
size: getByteSize(item.source.toString())
|
|
65
69
|
});
|
|
66
70
|
}
|
|
67
71
|
});
|
|
68
|
-
|
|
72
|
+
return {
|
|
73
|
+
builtAt: Date.now(),
|
|
69
74
|
assets: assets,
|
|
70
75
|
chunks: chunks,
|
|
71
76
|
modules: Object.values(moduleByFileName)
|
|
72
77
|
};
|
|
73
|
-
return output;
|
|
74
78
|
};
|
|
75
79
|
|
|
76
80
|
var NAME = 'webpackStats';
|
|
@@ -92,5 +96,5 @@ var webpackStats = function webpackStats(options) {
|
|
|
92
96
|
};
|
|
93
97
|
};
|
|
94
98
|
|
|
95
|
-
export { webpackStats };
|
|
99
|
+
export { bundleToWebpackStats, webpackStats };
|
|
96
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 const relativeModulePath = path.relative(\n process.cwd(),\n
|
|
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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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,9 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rollup-plugin-webpack-stats",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"private": false,
|
|
4
5
|
"license": "MIT",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"typings": "dist/index.d.ts",
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "Viorel Cojocaru",
|
|
10
|
+
"email": "vio@beanon.com",
|
|
11
|
+
"url": "https://beanon.com"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/vio/rollup-plugin-webpack-stats.git"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/vio/rollup-plugin-webpack-stats/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/vio/rollup-plugin-webpack-stats/blob/master/#readme",
|
|
7
21
|
"files": [
|
|
8
22
|
"dist",
|
|
9
23
|
"src"
|
|
@@ -30,17 +44,16 @@
|
|
|
30
44
|
"singleQuote": true,
|
|
31
45
|
"trailingComma": "es5"
|
|
32
46
|
},
|
|
33
|
-
"author": "Vio",
|
|
34
47
|
"module": "dist/rollup-plugin-webpack-stats.esm.js",
|
|
35
48
|
"devDependencies": {
|
|
36
49
|
"husky": "^8.0.3",
|
|
37
|
-
"rollup": "^
|
|
38
|
-
"size-limit": "^8.1.
|
|
50
|
+
"rollup": "^3.10.0",
|
|
51
|
+
"size-limit": "^8.1.1",
|
|
39
52
|
"tsdx": "^0.14.1",
|
|
40
53
|
"tslib": "^2.4.1",
|
|
41
54
|
"typescript": "^4.9.4"
|
|
42
55
|
},
|
|
43
56
|
"peerDependencies": {
|
|
44
|
-
"rollup": "^
|
|
57
|
+
"rollup": "^3.0.0"
|
|
45
58
|
}
|
|
46
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
|
@@ -89,18 +89,26 @@ export const bundleToWebpackStats = (
|
|
|
89
89
|
});
|
|
90
90
|
|
|
91
91
|
Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {
|
|
92
|
+
// Remove unexpected rollup null prefix
|
|
93
|
+
const normalizedModulePath = modulePath.replace('\u0000', '');
|
|
94
|
+
|
|
92
95
|
const relativeModulePath = path.relative(
|
|
93
96
|
process.cwd(),
|
|
94
|
-
|
|
97
|
+
normalizedModulePath
|
|
95
98
|
);
|
|
96
99
|
|
|
97
|
-
|
|
100
|
+
// Match webpack output - add current directory prefix for child modules
|
|
101
|
+
const relativeModulePathWithPrefix = relativeModulePath.match(/^\.\./)
|
|
102
|
+
? relativeModulePath
|
|
103
|
+
: `.${path.sep}${relativeModulePath}`;
|
|
104
|
+
|
|
105
|
+
const moduleEntry = moduleByFileName[relativeModulePathWithPrefix];
|
|
98
106
|
|
|
99
107
|
if (moduleEntry) {
|
|
100
108
|
moduleEntry.chunks.push(chunkId);
|
|
101
109
|
} else {
|
|
102
|
-
moduleByFileName[
|
|
103
|
-
name:
|
|
110
|
+
moduleByFileName[relativeModulePathWithPrefix] = {
|
|
111
|
+
name: relativeModulePathWithPrefix,
|
|
104
112
|
size: options.moduleOriginalSize
|
|
105
113
|
? moduleInfo.originalLength
|
|
106
114
|
: moduleInfo.renderedLength,
|
|
@@ -111,18 +119,17 @@ export const bundleToWebpackStats = (
|
|
|
111
119
|
} else if (item.type === 'asset') {
|
|
112
120
|
assets.push({
|
|
113
121
|
name: item.fileName,
|
|
114
|
-
size: getByteSize(item.source),
|
|
122
|
+
size: getByteSize(item.source.toString()),
|
|
115
123
|
});
|
|
116
124
|
} else {
|
|
117
125
|
// noop for unknown types
|
|
118
126
|
}
|
|
119
127
|
});
|
|
120
128
|
|
|
121
|
-
|
|
129
|
+
return {
|
|
130
|
+
builtAt: Date.now(),
|
|
122
131
|
assets,
|
|
123
132
|
chunks,
|
|
124
133
|
modules: Object.values(moduleByFileName),
|
|
125
134
|
};
|
|
126
|
-
|
|
127
|
-
return output;
|
|
128
135
|
};
|