rollup-plugin-webpack-stats
Advanced tools
Comparing version 0.0.2 to 0.0.3
import { Plugin } from 'rollup'; | ||
export declare const webpackStats: () => Plugin; | ||
import { BundleTransformOptions } from './transform'; | ||
interface WebpackStatsOptions extends BundleTransformOptions { | ||
/** | ||
* JSON file output fileName | ||
* default: webpack-stats.json | ||
*/ | ||
fileName?: string; | ||
} | ||
export declare const webpackStats: (options?: WebpackStatsOptions) => Plugin; | ||
export {}; |
@@ -9,2 +9,17 @@ 'use strict'; | ||
function _extends() { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
var getByteSize = function getByteSize(content) { | ||
@@ -16,3 +31,6 @@ if (typeof content === 'string') { | ||
}; | ||
var bundleToWebpackStats = function bundleToWebpackStats(bundle) { | ||
var bundleToWebpackStats = function bundleToWebpackStats(bundle, customOptions) { | ||
var options = _extends({ | ||
moduleOriginalSize: false | ||
}, customOptions); | ||
var items = Object.values(bundle); | ||
@@ -32,3 +50,3 @@ var assets = []; | ||
entry: item.isEntry, | ||
initial: item.isEntry, | ||
initial: !item.isDynamicEntry, | ||
files: [item.fileName], | ||
@@ -47,3 +65,3 @@ names: [item.name] | ||
name: relativeModulePath, | ||
size: moduleInfo.originalLength, | ||
size: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength, | ||
chunks: [chunkId] | ||
@@ -69,10 +87,14 @@ }; | ||
var NAME = 'webpackStats'; | ||
var webpackStats = function webpackStats() { | ||
var webpackStats = function webpackStats(options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
return { | ||
name: NAME, | ||
generateBundle: function generateBundle(_, bundle) { | ||
var output = bundleToWebpackStats(bundle); | ||
var _options; | ||
var output = bundleToWebpackStats(bundle, options); | ||
this.emitFile({ | ||
type: 'asset', | ||
fileName: 'webpack-stats.json', | ||
fileName: ((_options = options) == null ? void 0 : _options.fileName) || 'webpack-stats.json', | ||
source: JSON.stringify(output) | ||
@@ -79,0 +101,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("node:path"))&&"object"==typeof e&&"default"in e?e.default:e,n=function(e){return"string"==typeof e?Buffer.from(e).length:(null==e?void 0:e.length)||0};exports.webpackStats=function(){return{name:"webpackStats",generateBundle:function(e,s){var a=function(e){var s=Object.values(e),a=[],i=[],r={};return s.forEach((function(e){if("chunk"===e.type){a.push({name:e.fileName,size:n(e.code)});var s=e.name;i.push({id:s,entry:e.isEntry,initial:e.isEntry,files:[e.fileName],names:[e.name]}),Object.entries(e.modules).forEach((function(e){var n=e[0],a=e[1],i=t.relative(process.cwd(),n.replace("\0","")),u=r[i];u?u.chunks.push(s):r[i]={name:i,size:a.originalLength,chunks:[s]}}))}else"asset"===e.type&&a.push({name:e.fileName,size:n(e.source)})})),{assets:a,chunks:i,modules:Object.values(r)}}(s);this.emitFile({type:"asset",fileName:"webpack-stats.json",source:JSON.stringify(a)})}}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("node:path"))&&"object"==typeof e&&"default"in e?e.default:e;function n(){return(n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}var i=function(e){return"string"==typeof e?Buffer.from(e).length:(null==e?void 0:e.length)||0};exports.webpackStats=function(e){return void 0===e&&(e={}),{name:"webpackStats",generateBundle:function(r,a){var s,u=function(e,r){var a=n({moduleOriginalSize:!1},r),s=Object.values(e),u=[],o=[],l={};return s.forEach((function(e){if("chunk"===e.type){u.push({name:e.fileName,size:i(e.code)});var n=e.name;o.push({id:n,entry:e.isEntry,initial:!e.isDynamicEntry,files:[e.fileName],names:[e.name]}),Object.entries(e.modules).forEach((function(e){var i=e[0],r=e[1],s=t.relative(process.cwd(),i.replace("\0","")),u=l[s];u?u.chunks.push(n):l[s]={name:s,size:a.moduleOriginalSize?r.originalLength:r.renderedLength,chunks:[n]}}))}else"asset"===e.type&&u.push({name:e.fileName,size:i(e.source)})})),{assets:u,chunks:o,modules:Object.values(l)}}(a,e);this.emitFile({type:"asset",fileName:(null==(s=e)?void 0:s.fileName)||"webpack-stats.json",source:JSON.stringify(u)})}}}; | ||
//# sourceMappingURL=rollup-plugin-webpack-stats.cjs.production.min.js.map |
import path from 'node:path'; | ||
function _extends() { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
var getByteSize = function getByteSize(content) { | ||
@@ -9,3 +24,6 @@ if (typeof content === 'string') { | ||
}; | ||
var bundleToWebpackStats = function bundleToWebpackStats(bundle) { | ||
var bundleToWebpackStats = function bundleToWebpackStats(bundle, customOptions) { | ||
var options = _extends({ | ||
moduleOriginalSize: false | ||
}, customOptions); | ||
var items = Object.values(bundle); | ||
@@ -25,3 +43,3 @@ var assets = []; | ||
entry: item.isEntry, | ||
initial: item.isEntry, | ||
initial: !item.isDynamicEntry, | ||
files: [item.fileName], | ||
@@ -40,3 +58,3 @@ names: [item.name] | ||
name: relativeModulePath, | ||
size: moduleInfo.originalLength, | ||
size: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength, | ||
chunks: [chunkId] | ||
@@ -62,10 +80,14 @@ }; | ||
var NAME = 'webpackStats'; | ||
var webpackStats = function webpackStats() { | ||
var webpackStats = function webpackStats(options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
return { | ||
name: NAME, | ||
generateBundle: function generateBundle(_, bundle) { | ||
var output = bundleToWebpackStats(bundle); | ||
var _options; | ||
var output = bundleToWebpackStats(bundle, options); | ||
this.emitFile({ | ||
type: 'asset', | ||
fileName: 'webpack-stats.json', | ||
fileName: ((_options = options) == null ? void 0 : _options.fileName) || 'webpack-stats.json', | ||
source: JSON.stringify(output) | ||
@@ -72,0 +94,0 @@ }); |
@@ -32,2 +32,9 @@ import { OutputBundle } from 'rollup'; | ||
} | ||
export declare const bundleToWebpackStats: (bundle: OutputBundle) => WebpackStatsFiltered; | ||
export declare type BundleTransformOptions = { | ||
/** | ||
* Extract module original size or rendered size | ||
* default: false | ||
*/ | ||
moduleOriginalSize?: boolean; | ||
}; | ||
export declare const bundleToWebpackStats: (bundle: OutputBundle, customOptions?: BundleTransformOptions | undefined) => WebpackStatsFiltered; |
{ | ||
"name": "rollup-plugin-webpack-stats", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import { Plugin } from 'rollup'; | ||
import { bundleToWebpackStats } from './transform'; | ||
import { BundleTransformOptions, bundleToWebpackStats } from './transform'; | ||
const NAME = 'webpackStats'; | ||
export const webpackStats = (): Plugin => ({ | ||
interface WebpackStatsOptions extends BundleTransformOptions { | ||
/** | ||
* JSON file output fileName | ||
* default: webpack-stats.json | ||
*/ | ||
fileName?: string; | ||
} | ||
export const webpackStats = (options: WebpackStatsOptions = {}): Plugin => ({ | ||
name: NAME, | ||
generateBundle(_, bundle) { | ||
const output = bundleToWebpackStats(bundle); | ||
const output = bundleToWebpackStats(bundle, options); | ||
this.emitFile({ | ||
type: 'asset', | ||
fileName: 'webpack-stats.json', | ||
fileName: options?.fileName || 'webpack-stats.json', | ||
source: JSON.stringify(output), | ||
@@ -16,0 +24,0 @@ }); |
@@ -49,3 +49,16 @@ import path from 'node:path'; | ||
export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => { | ||
export type BundleTransformOptions = { | ||
/** | ||
* Extract module original size or rendered size | ||
* default: false | ||
*/ | ||
moduleOriginalSize?: boolean; | ||
}; | ||
export const bundleToWebpackStats = (bundle: OutputBundle, customOptions?: BundleTransformOptions): WebpackStatsFiltered => { | ||
const options = { | ||
moduleOriginalSize: false, | ||
...customOptions, | ||
}; | ||
const items = Object.values(bundle); | ||
@@ -70,5 +83,5 @@ | ||
entry: item.isEntry, | ||
initial: item.isEntry, | ||
initial: !item.isDynamicEntry, | ||
files: [item.fileName], | ||
names: [item.name] | ||
names: [item.name], | ||
}); | ||
@@ -86,3 +99,3 @@ | ||
name: relativeModulePath, | ||
size: moduleInfo.originalLength, | ||
size: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength, | ||
chunks: [chunkId], | ||
@@ -89,0 +102,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34600
369