rollup-plugin-webpack-stats
Advanced tools
Comparing version 0.2.0 to 0.2.1-beta.1
@@ -0,0 +0,0 @@ import { Plugin } from 'rollup'; |
@@ -0,8 +1,88 @@ | ||
'use strict'; | ||
'use strict' | ||
var path = require('path'); | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./rollup-plugin-webpack-stats.cjs.production.min.js') | ||
} else { | ||
module.exports = require('./rollup-plugin-webpack-stats.cjs.development.js') | ||
} | ||
const getByteSize = (content) => { | ||
if (typeof content === 'string') { | ||
return Buffer.from(content).length; | ||
} | ||
return content?.length || 0; | ||
}; | ||
const bundleToWebpackStats = (bundle, customOptions) => { | ||
const options = { | ||
moduleOriginalSize: false, | ||
...customOptions, | ||
}; | ||
const items = Object.values(bundle); | ||
const assets = []; | ||
const chunks = []; | ||
const moduleByFileName = {}; | ||
items.forEach(item => { | ||
if (item.type === 'chunk') { | ||
assets.push({ | ||
name: item.fileName, | ||
size: getByteSize(item.code), | ||
}); | ||
const chunkId = item.name; | ||
chunks.push({ | ||
id: chunkId, | ||
entry: item.isEntry, | ||
initial: !item.isDynamicEntry, | ||
files: [item.fileName], | ||
names: [item.name], | ||
}); | ||
Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => { | ||
// Remove unexpected rollup null prefix | ||
const normalizedModulePath = modulePath.replace('\u0000', ''); | ||
const relativeModulePath = path.relative(process.cwd(), normalizedModulePath); | ||
// Match webpack output - add current directory prefix for child modules | ||
const relativeModulePathWithPrefix = relativeModulePath.match(/^\.\./) | ||
? relativeModulePath | ||
: `.${path.sep}${relativeModulePath}`; | ||
const moduleEntry = moduleByFileName[relativeModulePathWithPrefix]; | ||
if (moduleEntry) { | ||
moduleEntry.chunks.push(chunkId); | ||
} | ||
else { | ||
moduleByFileName[relativeModulePathWithPrefix] = { | ||
name: relativeModulePathWithPrefix, | ||
size: options.moduleOriginalSize | ||
? moduleInfo.originalLength | ||
: moduleInfo.renderedLength, | ||
chunks: [chunkId], | ||
}; | ||
} | ||
}); | ||
} | ||
else if (item.type === 'asset') { | ||
assets.push({ | ||
name: item.fileName, | ||
size: getByteSize(item.source.toString()), | ||
}); | ||
} | ||
else ; | ||
}); | ||
return { | ||
builtAt: Date.now(), | ||
assets, | ||
chunks, | ||
modules: Object.values(moduleByFileName), | ||
}; | ||
}; | ||
const NAME = 'webpackStats'; | ||
const webpackStats = (options = {}) => ({ | ||
name: NAME, | ||
generateBundle(_, bundle) { | ||
const output = bundleToWebpackStats(bundle, options); | ||
this.emitFile({ | ||
type: 'asset', | ||
fileName: options?.fileName || 'webpack-stats.json', | ||
source: JSON.stringify(output), | ||
}); | ||
}, | ||
}); | ||
exports.bundleToWebpackStats = bundleToWebpackStats; | ||
exports.webpackStats = webpackStats; | ||
//# sourceMappingURL=index.js.map |
import { OutputBundle } from 'rollup'; | ||
export declare type WebpackStatsFilteredAsset = { | ||
export type WebpackStatsFilteredAsset = { | ||
name: string; | ||
@@ -32,3 +32,3 @@ size?: number; | ||
} | ||
export declare type BundleTransformOptions = { | ||
export type BundleTransformOptions = { | ||
/** | ||
@@ -40,2 +40,2 @@ * Extract module original size or rendered size | ||
}; | ||
export declare const bundleToWebpackStats: (bundle: OutputBundle, customOptions?: BundleTransformOptions | undefined) => WebpackStatsFiltered; | ||
export declare const bundleToWebpackStats: (bundle: OutputBundle, customOptions?: BundleTransformOptions) => WebpackStatsFiltered; |
{ | ||
"name": "rollup-plugin-webpack-stats", | ||
"version": "0.2.0", | ||
"version": "0.2.1-beta.1", | ||
"private": false, | ||
@@ -29,12 +29,12 @@ "license": "MIT", | ||
"scripts": { | ||
"start": "tsdx watch", | ||
"build": "tsdx build", | ||
"test": "tsdx test", | ||
"lint": "tsdx lint", | ||
"prepare": "tsdx build", | ||
"analyze": "size-limit --why" | ||
"build": "rollup -c rollup.config.mjs", | ||
"lint": "exit 0", | ||
"test:unit": "vitest test/unit", | ||
"test:package": "vitest test/package", | ||
"bump": "./scripts/bump.sh", | ||
"release": "./scripts/release.sh" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "tsdx lint" | ||
"pre-commit": "npm run lint" | ||
} | ||
@@ -48,10 +48,14 @@ }, | ||
}, | ||
"module": "dist/rollup-plugin-webpack-stats.esm.js", | ||
"devDependencies": { | ||
"husky": "^8.0.3", | ||
"rollup": "^3.10.0", | ||
"size-limit": "^8.1.1", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^2.4.1", | ||
"typescript": "^4.9.4" | ||
"@release-it/conventional-changelog": "7.0.0", | ||
"@rollup/plugin-typescript": "11.1.3", | ||
"@tsconfig/node14": "14.1.0", | ||
"@types/node": "20.5.6", | ||
"dotenv": "16.3.1", | ||
"husky": "8.0.3", | ||
"release-it": "16.1.5", | ||
"rollup": "3.28.1", | ||
"tslib": "2.6.2", | ||
"typescript": "5.2.2", | ||
"vitest": "0.34.3" | ||
}, | ||
@@ -58,0 +62,0 @@ "peerDependencies": { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
1
0
18603
11
9
269
1