Git Product home page Git Product logo

bundle-internals's Introduction

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",
  // ...

bundle-internals's People

Contributors

dependabot[bot] avatar pyatyispyatil avatar smelukov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

pyatyispyatil

bundle-internals's Issues

Add denormalization helper

  • Add a helper that resolves all data fields that need to be resolved manually
  • Add plugin option to auto-denormalize fields

More jora query examples

Hey, greet libs. But are you can create more examples query, because Jora query is new for me and you have useful queries
For example:
Find reasons because module required

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.