rollup-plugin-webpack-stats 0.0.2 → 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 +5 -5
- package/dist/index.d.ts +10 -1
- package/dist/rollup-plugin-webpack-stats.cjs.development.js +29 -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 +29 -7
- package/dist/rollup-plugin-webpack-stats.esm.js.map +1 -1
- package/dist/transform.d.ts +8 -1
- package/package.json +1 -1
- package/src/index.ts +12 -4
- package/src/transform.ts +31 -9
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://www.npmjs.com/package/rollup-plugin-webpack-stats)
|
|
7
7
|

|
|
8
|
+
[](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
|
|
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');
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import { Plugin } from 'rollup';
|
|
2
|
-
|
|
2
|
+
import { BundleTransformOptions } from './transform';
|
|
3
|
+
interface WebpackStatsOptions extends BundleTransformOptions {
|
|
4
|
+
/**
|
|
5
|
+
* JSON file output fileName
|
|
6
|
+
* default: webpack-stats.json
|
|
7
|
+
*/
|
|
8
|
+
fileName?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const webpackStats: (options?: WebpackStatsOptions) => Plugin;
|
|
11
|
+
export {};
|
|
@@ -4,7 +4,22 @@ 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('
|
|
7
|
+
var path = _interopDefault(require('path'));
|
|
8
|
+
|
|
9
|
+
function _extends() {
|
|
10
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
11
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
12
|
+
var source = arguments[i];
|
|
13
|
+
for (var key in source) {
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
15
|
+
target[key] = source[key];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
return _extends.apply(this, arguments);
|
|
22
|
+
}
|
|
8
23
|
|
|
9
24
|
var getByteSize = function getByteSize(content) {
|
|
10
25
|
if (typeof content === 'string') {
|
|
@@ -12,7 +27,10 @@ var getByteSize = function getByteSize(content) {
|
|
|
12
27
|
}
|
|
13
28
|
return (content == null ? void 0 : content.length) || 0;
|
|
14
29
|
};
|
|
15
|
-
var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
|
|
30
|
+
var bundleToWebpackStats = function bundleToWebpackStats(bundle, customOptions) {
|
|
31
|
+
var options = _extends({
|
|
32
|
+
moduleOriginalSize: false
|
|
33
|
+
}, customOptions);
|
|
16
34
|
var items = Object.values(bundle);
|
|
17
35
|
var assets = [];
|
|
18
36
|
var chunks = [];
|
|
@@ -27,7 +45,7 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
|
|
|
27
45
|
chunks.push({
|
|
28
46
|
id: chunkId,
|
|
29
47
|
entry: item.isEntry,
|
|
30
|
-
initial: item.
|
|
48
|
+
initial: !item.isDynamicEntry,
|
|
31
49
|
files: [item.fileName],
|
|
32
50
|
names: [item.name]
|
|
33
51
|
});
|
|
@@ -41,7 +59,7 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
|
|
|
41
59
|
} else {
|
|
42
60
|
moduleByFileName[relativeModulePath] = {
|
|
43
61
|
name: relativeModulePath,
|
|
44
|
-
size: moduleInfo.originalLength,
|
|
62
|
+
size: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength,
|
|
45
63
|
chunks: [chunkId]
|
|
46
64
|
};
|
|
47
65
|
}
|
|
@@ -62,14 +80,18 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
|
|
|
62
80
|
};
|
|
63
81
|
|
|
64
82
|
var NAME = 'webpackStats';
|
|
65
|
-
var webpackStats = function webpackStats() {
|
|
83
|
+
var webpackStats = function webpackStats(options) {
|
|
84
|
+
if (options === void 0) {
|
|
85
|
+
options = {};
|
|
86
|
+
}
|
|
66
87
|
return {
|
|
67
88
|
name: NAME,
|
|
68
89
|
generateBundle: function generateBundle(_, bundle) {
|
|
69
|
-
var
|
|
90
|
+
var _options;
|
|
91
|
+
var output = bundleToWebpackStats(bundle, options);
|
|
70
92
|
this.emitFile({
|
|
71
93
|
type: 'asset',
|
|
72
|
-
fileName: 'webpack-stats.json',
|
|
94
|
+
fileName: ((_options = options) == null ? void 0 : _options.fileName) || 'webpack-stats.json',
|
|
73
95
|
source: JSON.stringify(output)
|
|
74
96
|
});
|
|
75
97
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup-plugin-webpack-stats.cjs.development.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from '
|
|
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","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AAI,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("
|
|
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 '
|
|
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,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,GAuDrE,OArDAL,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,gBAAEiB,OAAYC,OAC3CC,EAAqBC,EAAKC,SAC9BC,QAAQC,MACRN,EAAWO,QAAQ,KAAU,KAGzBC,EAAc1B,EAAiBoB,GAEjCM,EACFA,EAAY3B,OAAOK,KAAKI,GAExBR,EAAiBoB,GAAsB,CACrChC,KAAMgC,EACNd,KAAMnB,EAAQO,mBACVyB,EAAWQ,eACXR,EAAWS,eACf7B,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,IC1GR8B,CAAqBvC,EAAQJ,GAE5C4C,KAAKC,SAAS,CACZ7B,KAAM,QACNE,mBAAUlB,UAAA8C,EAAS5B,WAAY,qBAC/BwB,OAAQK,KAAKC,UAAU3C"}
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
import path from '
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
function _extends() {
|
|
4
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
5
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
6
|
+
var source = arguments[i];
|
|
7
|
+
for (var key in source) {
|
|
8
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
9
|
+
target[key] = source[key];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
return _extends.apply(this, arguments);
|
|
16
|
+
}
|
|
2
17
|
|
|
3
18
|
var getByteSize = function getByteSize(content) {
|
|
4
19
|
if (typeof content === 'string') {
|
|
@@ -6,7 +21,10 @@ var getByteSize = function getByteSize(content) {
|
|
|
6
21
|
}
|
|
7
22
|
return (content == null ? void 0 : content.length) || 0;
|
|
8
23
|
};
|
|
9
|
-
var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
|
|
24
|
+
var bundleToWebpackStats = function bundleToWebpackStats(bundle, customOptions) {
|
|
25
|
+
var options = _extends({
|
|
26
|
+
moduleOriginalSize: false
|
|
27
|
+
}, customOptions);
|
|
10
28
|
var items = Object.values(bundle);
|
|
11
29
|
var assets = [];
|
|
12
30
|
var chunks = [];
|
|
@@ -21,7 +39,7 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
|
|
|
21
39
|
chunks.push({
|
|
22
40
|
id: chunkId,
|
|
23
41
|
entry: item.isEntry,
|
|
24
|
-
initial: item.
|
|
42
|
+
initial: !item.isDynamicEntry,
|
|
25
43
|
files: [item.fileName],
|
|
26
44
|
names: [item.name]
|
|
27
45
|
});
|
|
@@ -35,7 +53,7 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
|
|
|
35
53
|
} else {
|
|
36
54
|
moduleByFileName[relativeModulePath] = {
|
|
37
55
|
name: relativeModulePath,
|
|
38
|
-
size: moduleInfo.originalLength,
|
|
56
|
+
size: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength,
|
|
39
57
|
chunks: [chunkId]
|
|
40
58
|
};
|
|
41
59
|
}
|
|
@@ -56,14 +74,18 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
|
|
|
56
74
|
};
|
|
57
75
|
|
|
58
76
|
var NAME = 'webpackStats';
|
|
59
|
-
var webpackStats = function webpackStats() {
|
|
77
|
+
var webpackStats = function webpackStats(options) {
|
|
78
|
+
if (options === void 0) {
|
|
79
|
+
options = {};
|
|
80
|
+
}
|
|
60
81
|
return {
|
|
61
82
|
name: NAME,
|
|
62
83
|
generateBundle: function generateBundle(_, bundle) {
|
|
63
|
-
var
|
|
84
|
+
var _options;
|
|
85
|
+
var output = bundleToWebpackStats(bundle, options);
|
|
64
86
|
this.emitFile({
|
|
65
87
|
type: 'asset',
|
|
66
|
-
fileName: 'webpack-stats.json',
|
|
88
|
+
fileName: ((_options = options) == null ? void 0 : _options.fileName) || 'webpack-stats.json',
|
|
67
89
|
source: JSON.stringify(output)
|
|
68
90
|
});
|
|
69
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup-plugin-webpack-stats.esm.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from '
|
|
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 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;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,I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AEtB,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;;;;"}
|
package/dist/transform.d.ts
CHANGED
|
@@ -29,4 +29,11 @@ export interface WebpackStatsFiltered {
|
|
|
29
29
|
chunks?: Array<WebpackStatsFilteredChunk>;
|
|
30
30
|
modules?: Array<WebpackStatsFilteredRootModule>;
|
|
31
31
|
}
|
|
32
|
-
export declare
|
|
32
|
+
export declare type BundleTransformOptions = {
|
|
33
|
+
/**
|
|
34
|
+
* Extract module original size or rendered size
|
|
35
|
+
* default: false
|
|
36
|
+
*/
|
|
37
|
+
moduleOriginalSize?: boolean;
|
|
38
|
+
};
|
|
39
|
+
export declare const bundleToWebpackStats: (bundle: OutputBundle, customOptions?: BundleTransformOptions | undefined) => WebpackStatsFiltered;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { Plugin } from 'rollup';
|
|
2
2
|
|
|
3
|
-
import { bundleToWebpackStats } from './transform';
|
|
3
|
+
import { BundleTransformOptions, bundleToWebpackStats } from './transform';
|
|
4
4
|
|
|
5
5
|
const NAME = 'webpackStats';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
interface WebpackStatsOptions extends BundleTransformOptions {
|
|
8
|
+
/**
|
|
9
|
+
* JSON file output fileName
|
|
10
|
+
* default: webpack-stats.json
|
|
11
|
+
*/
|
|
12
|
+
fileName?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const webpackStats = (options: WebpackStatsOptions = {}): Plugin => ({
|
|
8
16
|
name: NAME,
|
|
9
17
|
generateBundle(_, bundle) {
|
|
10
|
-
const output = bundleToWebpackStats(bundle);
|
|
18
|
+
const output = bundleToWebpackStats(bundle, options);
|
|
11
19
|
|
|
12
20
|
this.emitFile({
|
|
13
21
|
type: 'asset',
|
|
14
|
-
fileName: 'webpack-stats.json',
|
|
22
|
+
fileName: options?.fileName || 'webpack-stats.json',
|
|
15
23
|
source: JSON.stringify(output),
|
|
16
24
|
});
|
|
17
25
|
},
|
package/src/transform.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import path from '
|
|
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
|
|
29
|
+
export interface WebpackStatsFilteredRootModule
|
|
30
|
+
extends WebpackStatsFilteredModule {
|
|
30
31
|
modules?: Array<WebpackStatsFilteredConcatenatedModule>;
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -46,7 +47,23 @@ const getByteSize = (content: string | Buffer): number => {
|
|
|
46
47
|
return content?.length || 0;
|
|
47
48
|
};
|
|
48
49
|
|
|
49
|
-
export
|
|
50
|
+
export type BundleTransformOptions = {
|
|
51
|
+
/**
|
|
52
|
+
* Extract module original size or rendered size
|
|
53
|
+
* default: false
|
|
54
|
+
*/
|
|
55
|
+
moduleOriginalSize?: boolean;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const bundleToWebpackStats = (
|
|
59
|
+
bundle: OutputBundle,
|
|
60
|
+
customOptions?: BundleTransformOptions
|
|
61
|
+
): WebpackStatsFiltered => {
|
|
62
|
+
const options = {
|
|
63
|
+
moduleOriginalSize: false,
|
|
64
|
+
...customOptions,
|
|
65
|
+
};
|
|
66
|
+
|
|
50
67
|
const items = Object.values(bundle);
|
|
51
68
|
|
|
52
69
|
const assets: Array<WebpackStatsFilteredAsset> = [];
|
|
@@ -54,7 +71,7 @@ export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered
|
|
|
54
71
|
|
|
55
72
|
const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};
|
|
56
73
|
|
|
57
|
-
items.forEach(
|
|
74
|
+
items.forEach(item => {
|
|
58
75
|
if (item.type === 'chunk') {
|
|
59
76
|
assets.push({
|
|
60
77
|
name: item.fileName,
|
|
@@ -66,13 +83,16 @@ export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered
|
|
|
66
83
|
chunks.push({
|
|
67
84
|
id: chunkId,
|
|
68
85
|
entry: item.isEntry,
|
|
69
|
-
initial: item.
|
|
86
|
+
initial: !item.isDynamicEntry,
|
|
70
87
|
files: [item.fileName],
|
|
71
|
-
names: [item.name]
|
|
88
|
+
names: [item.name],
|
|
72
89
|
});
|
|
73
90
|
|
|
74
91
|
Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {
|
|
75
|
-
const relativeModulePath = path.relative(
|
|
92
|
+
const relativeModulePath = path.relative(
|
|
93
|
+
process.cwd(),
|
|
94
|
+
modulePath.replace('\u0000', '')
|
|
95
|
+
);
|
|
76
96
|
|
|
77
97
|
const moduleEntry = moduleByFileName[relativeModulePath];
|
|
78
98
|
|
|
@@ -81,7 +101,9 @@ export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered
|
|
|
81
101
|
} else {
|
|
82
102
|
moduleByFileName[relativeModulePath] = {
|
|
83
103
|
name: relativeModulePath,
|
|
84
|
-
size:
|
|
104
|
+
size: options.moduleOriginalSize
|
|
105
|
+
? moduleInfo.originalLength
|
|
106
|
+
: moduleInfo.renderedLength,
|
|
85
107
|
chunks: [chunkId],
|
|
86
108
|
};
|
|
87
109
|
}
|