Giter Site home page Giter Site logo

microsoft / webpack-bundle-compare Goto Github PK

View Code? Open in Web Editor NEW
157.0 7.0 18.0 2.29 MB

A tool for comparing webpack bundle stats

Home Page: https://happy-water-0887b0b1e.azurestaticapps.net/#/

License: MIT License

TypeScript 89.16% CSS 0.85% JavaScript 1.38% SCSS 8.62%
webpack

webpack-bundle-compare's Introduction

@mixer/webpack-bundle-compare

This is a tool that allows you to compare webpack bundle analysis files over time. Check it out here.

Usage

The bundle comparison tool takes URLs of webpack stat outputs and displays them. You can use the JSON output from the webpack-bundle-analyzer, but we also include a plugin here if you don't use that package.

Using the Plugin

First, install the plugin.

npm install --save-dev @mixer/webpack-bundle-compare

Then, add it to your webpack.config.js file.

+const { BundleComparisonPlugin } = require('@mixer/webpack-bundle-compare');

...

   plugins: [
+    new BundleComparisonPlugin()
   ]

By default, this'll output a file named stats.msp.gz in your build output. This is a gzipped msgpack file--for large projects webpack bundle stats can get pretty big and slow down your build, so we try to make it fast. You can configure the output format and filename by passing options to the plugin:

new BundleComparisonPlugin({
  // File to create, relative to the webpack build output path:
  file: 'myStatsFile.msp.gz',
  // Format to output, "msgpack" by default:
  format: 'msgpack' | 'json',
  // Whether to gzip the output, defaults to true:
  gzip: true | false,
})

Once you have this file, you can upload it somewhere such as Azure blob storage, and serve it in the tool. The module exposes a convenient way to get a direct preloaded link in the tool:

const { getComparisonAddress } = require('@mixer/webpack-bundle-compare');
const link = getComparisonAddress([
  'http://example.com/stats1.msp.gz',
  'http://example.com/stats1.msp.gz',
])

console.log('See your comparison at:', link);

Contributing

Architecture

It's a React/Redux app. We pull webpack analysis JSON down from URLs, process them, and output UI. State is driven via Redux, and the parsing and unzipping of the (potentially very large) webpack stat files happen in a webworker. Actions sent in the redux state are mirrored to the webworker, and in turn the webworker and send actions which get fired back to the host application. The work we do atop the stats file is not particularly interesting--an assortment of parsing, walking, and graph generation functions.

Iteration

To develop against the UI:

  1. Create a folder called "public/samples", and place JSON files in there. Or use the ones we already have preloaded.
  2. Set the WBC_FILES environment variable to a comma-delimited list of the filenames you placed in there.
  3. Running the webpack dev server via npm start will now serve the files you have placed in there.

webpack-bundle-compare's People

Contributors

alina-zaieva avatar azu avatar christiango avatar connor4312 avatar dependabot[bot] avatar dryzhkov avatar markionium avatar microsoft-github-policy-service[bot] avatar sverrejoh avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

webpack-bundle-compare's Issues

out of memory crash when uploading a stats msgpack of ~10MB

I'm trying to import some very big stats file in msgpack and gzipped, but unfortunately the stats must be too big that the application runs out of memory. I've tried to debug the issue but it is very hard for me.

Unfortunately I can't share the stats file as it occurs on a private project. But I can tell you that the generated stats is ~10MB

How can I solve the problem? any support is very appreciated

image

Support for uploading stats file from local file system

Thanks for sharing this awesome tool! We've already integrated it into our build pipeline for Office Online.

One thing that would be great would be the ability to choose files from the local file system for comparison, similar to what webpack analyse does (though they don't support the URL blob upload). The scenario here would be for developers wanting to see the impact of a change in a local branch before publishing a PR.

Was thinking that the FileReader API should make this possible

Requesting ideas to Improve the tree-shaking analysis

Hello, Thanks for the awesome compare tool ๐Ÿ‘

I've noticed that the below code block is being used to understand if require (cjs) is being used instead of a esmodule and hence marking it as a non-treeshakable module

export const getImportType = (importedModule: StatsModule) => {
let flags = 0;
for (const reason of getReasons(importedModule)) {
if (reason.type) {
flags |= reason.type.includes('cjs')
? ImportType.CommonJs
: reason.type.includes('harmony')
? ImportType.EsModule
: ImportType.Unknown;
}
}
return flags;
};

if (moduleType & ImportType.EsModule && !(moduleType & ImportType.CommonJs)) {

Many node modules are still exporting cjs files but still take care of tree-shaking.
For e.g. using require('lodash/get') will make sure that only the files required for get function are bundled in the final bundle created by webpack
But this tool marks lodash as Not Tree-Shaken

This is hence leading to a manual analysis to cross-verify of all such modules reported by the tool.
Other such complaints for Not Tree-Shaken were for modules such as axios, css-loader, style-loader, @babel/runtime etc.,

Can someone please share the idea/motivation behind showing the Not Tree-Shaken alert for a better understanding and ideas on the improvement we can do so that users can see correct percentage of tree-shaken modules in the final dashboard

Thanks again for all the great work!!

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.