Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@webpack-bundle-analyzer/bundle-parser

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webpack-bundle-analyzer/bundle-parser

Maps webpack bundled output files to the modules based on the given webpack stats object

  • 3.0.0-alpha.2
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@webpack-bundle-analyzer/bundle-parser

Calculates module sizes from webpack output files.

Install

npm install --save @webpack-bundle-analyzer/bundle-parser

Usage

const parseBundle = require('@webpack-bundle-analyzer/bundle-parser');
const Logger = require('@webpack-bundle-analyzer/logger');

const fs = require('fs');
const webpackStats = JSON.parse(
  fs.readFileSync('webpack/output/path/stats.json', 'utf8')
);

const logger = new Logger('info');

const moduleSizeData = parseBundle(
  webpackStats,
  'webpack/output/path',
  logger
);

console.log(JSON.stringify(moduleSizeData, null, 2));

Example output:

[
  {
    "label": "bundle.js",
    "statSize": 141,
    "parsedSize": 445,
    "gzipSize": 178,
    "groups": [
      {
        "label": "my-app",
        "path": "./my-app",
        "statSize": 141,
        "parsedSize": 332,
        "gzipSize": 119,
        "groups": [
          {
            "label": "src",
            "path": "./my-app/src",
            "statSize": 141,
            "parsedSize": 332,
            "gzipSize": 119,
            "groups": [
              {
                "id": 0,
                "label": "index.js",
                "path": "./my-app/src/index.js",
                "statSize": 54,
                "parsedSize": 131,
                "gzipSize": 93
              },
              {
                "id": 1,
                "label": "a.js",
                "path": "./my-app/src/a.js",
                "statSize": 29,
                "parsedSize": 67,
                "gzipSize": 73
              },
              {
                "id": 2,
                "label": "b.js",
                "path": "./my-app/src/b.js",
                "statSize": 29,
                "parsedSize": 67,
                "gzipSize": 73
              },
              {
                "id": 3,
                "label": "a-clone.js",
                "path": "./my-app/src/a-clone.js",
                "statSize": 29,
                "parsedSize": 67,
                "gzipSize": 73
              }
            ]
          }
        ]
      }
    ]
  }
]

Options

parseBundle(
  bundleStats: object,
  bundleDir: string,
  options: {
    logger: Logger
  }
);
NameTypeDescription
bundleStats{Object}webpack compilation information as a JSON object. This is the output of stats.toJson() webpack Node.js API.
bundleDir{String}Path to directory containing webpack output files, i.e. the value of output.path webpack config.
options.logger{Logger}An instance of a special Logger class also used in webpack-bundle-analyzer.

Size definitions

Data contains three sizes for each module if bundle parsing has succeeded, or only statSize if bundle parsing has failed for some reason.

statSize

The "input" size of modules, before any transformations like minification.

parsedSize

The "output" size of modules. If you're using a webpack plugin such as Uglify, then this value will reflect the minified size of your code.

gzipSize

Size approximation of running the parsed modules through gzip compression.

Gzip sizes of folders are calculated by concatenating the parsed sources of all modules inside a folder and running gzip-size over it.

Troubleshooting

Some inner modules are missing from the data

This is a known caveat when webpack.optimize.ModuleConcatenationPlugin is used. The way ModuleConcatenationPlugin works is that it merges multiple modules into a single one, and so that resulting module doesn't have edges anymore.

If you are interested to drill down to exact dependencies, try parsing output without ModuleConcatenationPlugin applied. See issue #115 for more discussion.

Maintainers


Yuriy Grunin

Vesa Laakso

Keywords

FAQs

Package last updated on 04 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc