npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bundle-internals

v1.2.0

Published

The webpack plugin that collects a debug information about your webpack bundle (e.g. bundled modules, input entry points, and output assets)

Downloads

11

Readme

Bundle Internals Plugin

The webpack plugin that collects a debug information about your webpack bundle (e.g. bundled modules, input entry points, and output assets)

npm

Usage

npm i bundle-internals

const BundleInternalsPlugin = require('bundle-internals');

config.plugins.push(new BundleInternalsPlugin());

Options

saveTo: string

Allow to dump a debug data to specified file (relative an output directory)

new BundleInternalsPlugin({
    saveTo: 'debug.json'
});

runMode: string

One of the values:

  • all - run plugin on watch and non-watch build
  • non-watch - run plugin only on non-watch build
  • watch - run plugin only on watch build

runMode is all by default

new BundleInternalsPlugin({
    runMode: 'watch'
});

resolve: boolean

Resolves payload before pass it to the data-hook

new BundleInternalsPlugin({
    resolve: true
});

resolve is false by default

Don't mix resolve and saveTo options because resolve makes a recursive JSON that can't be stringified If you really want to save recursive JSON then use some specialized tools (e.g. flatted)

Hooks

data(payload)

const bundleInternalsPlugin = new BundleInternalsPlugin()
bundleInternalsPlugin.hooks.data.tap('my-plugin', payload => {
    console.log(payload);
})

Data format

Data format described in types.d.ts

Data denormalization/resolving

Some data fields contain only ids and need to denormalize/resolve. For example file field in data.input.modules contain the only id of the file and we need to resolve it from data.input.files:

data.input.modules.forEach(module => {
    module.file = data.input.files.find(file => module.file === file.path)
});

Or you can use builtin resolve function:

const BundleInternalsPlugin = require('bundle-internals');

const bundleInternalsPlugin = new BundleInternalsPlugin()
bundleInternalsPlugin.hooks.data.tap('my-plugin', payload => {
    BundleInternalsPlugin.resolve(payload);
    console.log(payload);
});

Or use resolve option:

new BundleInternalsPlugin({
    resolve: true
});

Why not a builtin webpack Stats object?

Its too huge to analyze ;)

Data Analyzing

This plugin will be used in Webpack Runtime Analyzer V2

But for now, you can get the raw bundle internal data and analyze it manually.

It's just a JSON and you may use any tools to analyze and visualize it

For example, you may load it to Jora Sandbox and make some interesting queries to it.

Jora Sandbox is a sandbox for the Jora query engine that allows you to query and aggregate any data from JSON.

For example...

Used node modules

Jora Query:

input.files.nodeModule
  .group(<name>)
  .({name: key, version: value.version.sort()})
  .sort(<name>)

Result:

[
  { name: "@babel/polyfill", version: ["7.4.4"] },
  { name: "@babel/runtime", version: ["7.5.5"] },
  { name: "@firebase/app", version: ["0.1.10"] },
  { name: "@firebase/messaging", version: ["0.1.9"] },
  { name: "@firebase/util", version: ["0.1.10", "0.1.8"] },
  { name: "@sentry/browser", version: ["4.6.6"] },
  // ...
]

The most required modules

Jora Query:

input.modules.sort(reasons.size() desc).id

Result:

[
  "./node_modules/react/index.js",
  "./node_modules/prop-types/index.js",
  "./node_modules/react-redux/lib/index.js",
  "./node_modules/lodash/get.js",
  "./node_modules/@babel/polyfill/node_modules/core-js/modules/  _export.js",
  "./node_modules/react-dom/index.js",
  // ...