Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

vite-bundle-analyzer

nonzzz91.4kMIT0.16.0TypeScript support: included

a modern vite bundle analyzer tool

vite, rollup, rollup-plugin, vite-plugin, bundle-analyzer, rollup-bundle-analyzer

readme

vite-bundle-analyzer

Awesome

[!WARNING] Vite's enable minify by default.There for you will see that the parsed size is larger than actual size.This is because the bundle info provide by rollup isn't compressed.(If you care about this problem you can choose anothr plugins.)

Install

$ yarn add vite-bundle-analyzer -D

# or

$ npm install vite-bundle-analyzer -D

Usage

import { defineConfig } from 'vite'

import { analyzer } from 'vite-bundle-analyzer'

export default defineConfig({
  plugins: [
    // ...your plugin
    analyzer()
  ]
})

// If you are using it in rollup or others support rollup plugin system you can import 'adapter' from package.
// Then use it with adapter(analyzer())

Options

params type default description
analyzerMode server|static|json|function server In server will create a static server to preview.
fileName string stats The name of the static product.(No suffix name)
reportTitle string plugin name Report website title.
gzipOptions Record<string,any> {} Compression options. (Details see zlib module)
analyzerPort number|'auto' 8888 static server port.
openAnalyzer boolean true Open the static website. (Only works on analyzerMode is server or static )
defaultSizes stat|parsed|gzip stat The default type selected in the client page
summary boolean true Show full chunk info to stdout.

ClI

This plugin provides cli util analyze. Add --help to check actual options. It can be used like:

$ analyze -c "your vite config path"

Sponsors

Contributions

Contributions are welcome! If you find a bug or want to add a new feature, please open an issue or submit a pull request.

Author and contributors

Kanno Aleksandr Mitskevich mengdaoshizhongxinyang

DEBUG

If you're using vite you can get the logs with vite build --debug and then extreact the part relevant to analyze plugin. Or using cross-env to setup ANALYZE_DEBUG=true in your local. env.

Why i get the chunk size is empty?

If you're use a plugin that break the sourcemap it will affect the analyze plugin. I know it's stupid, But is the way to get the size close to the actual size. Like @vitejs/plugin-legacy don't prvide the correctly sourcemap for legacy chunk. For some reason, no analysis will be provided for those module.

Why when i specify analyzerMode as static and set openAnalyzer as false don't create a liviing server?

I don't want to add new option to control living server.

For vite based framework or library!!!

If you're using vitepress or remix or qwik and etc who based on the vite framework. Normally it will run two vite instance during build phase. So you should ensure that analyzerMode as server.(If you pass static or json for the analyzerMode i can't promise the final result.) Like vitpress will remove something (I don't know why? Maybe it's run with race?)

Integrated

Integrate this plugin into your rollup/vite tool. The following is a list of exposed APIs.

// For integrate it as custom analyzer

// Returns the HTML string
declare function renderView(analyzeModule: Module[], options: RenderOptions): Promise<string>

// Create a static living server.
declare function createServer(): CreateServerContext

declare function openBrowser(address: string): void

declare function injectHTMLTag(options: InjectHTMLTagOptions): string

declare class SSE {
  private activeStreams
  serverEventStream(req: http.IncomingMessage, res: http.ServerResponse): void
  sendEvent(event: string, data: string): void
  private removeStream
}

// example

const server = createServer()

server.get('/', async (c) => {
  let html = await renderView(data, { title: 'Vite Bundle Analyzer', mode: 'parsed' })
  c.res.writeHead(200, { 'Content-Type': 'text/html', 'Cache-Control': 'no-cache' })
  c.res.write(html)
  c.res.end()
})

server.listen(3000)

// If you want set this plugin in rollup output plugins. you should wrapper plugin `generateBundle` by your self.

const { api, generateBundle, ...rest } = analyzer()

const data = []

const myAnalyzerPlugin = {
  ...reset,
  api,
  async generateBundle(...args) {
    await generateBundle.apply(this, args)
    data.push(api.processModule())
  }
}

// .... your logic

LICENSE

MIT

changelog

0.16.0

  • Better custom integrate.
  • Fix adapter type error.
  • Support view brotli size.
  • Display no-js file.

0.16.0-beta.4

  • Fix adapter type error.

0.16.0-beta.3

Change hook order.

0.16.0-beta.2

  • Add Brotli size.
  • Display no-js files.

0.16.0-beta.1

Add more friendly API for integrate.

0.15.2

Expose render and other methods to better integrate into custom tools.

0.15.1

  • Revert the recent change to avoid bundling crash. (This usually happends when running mulitple instances.)

0.15.0

Improves

  • Support vite6.
  • Reduce bundle size.
  • Improve plugin integration support

0.14.3

Bump client deps.

0.14.2

Patches

  • Fix type='module' can't work.

0.14.1

Patches

  • Fix error shebang.

0.14.0

Feature & Improves

  • Add a simple cli tool. use like:
$ analyze -c ./vite.config.ts
  • Adjust treemap background color

0.13.1

Patches

  • Fix the fuck vitepress static generator can't work!!!

0.13.0

Major

Replace @carrotsearch/foamtree with squarified. For some reason i think the two library are similar. (And the new one can reduce 200kb) And the new library can better customize the function.

Before v0.13.0 the client look like classic

The new client

now

0.12.1

Better debug log info.

0.12.0

Improves

0.11.1

Patches

  • Fix #38

0.11.0

Improves & Features

  • Add new option defaultSizes. #19
  • Static mode support generating living server.(This version will open the client automatically, If you don't want please set openAnalyzer as false.) #37

0.10.6

  • Make default options happy.

credits

@a145789

0.10.5

  • Reduce debug info package size.
  • Makesure tool can be work.

0.10.4

  • Add debug info.

0.10.3

Patches

  • Fix static report does not work. #29

0.10.2

Patches

  • Respect output options.

0.10.1

Patches

  • Fix server mode should ensure the safe port.

0.10.0

Improve

  • Using @jridgewell/source-map replace source-map. It can reduce 200kb at install stage.
  • Perf client rendering logic.

0.9.4

Patches

  • Fix the problem of exit of generate task.

credits

@paulcarroll

0.9.3

Improve

  • Reduce package size.

Patches

  • Fix counting size should skip unknown assets.
  • Fix openAnalyzer can't work on WSL/WSL2.

0.9.2

  • Reduce package size.

0.9.1

Patches

  • Fix use absolute path for working directory. #17

credits

@TSmota

0.9.0

Features

  • Add rollup adapter.
import { adapter, analyzer } from 'vite-bundle-analyzer'

plugins: ;
;[adapter(analyzer())]

0.8.3

Patches

  • Fix the possible deadlock when generating stats.

0.8.2

Patches

  • Fix analyzerPort typo.

0.8.1

Patches

  • Using javaScript String index to computing sourcemap.

0.8.0

Improve & Features

  • Now file import with query suffix(Like worker and etc) can be collect.
  • Module size nearly the actullay size more.
  • Remove collect rest module size anymore.

0.7.0

Improve

  • Sub module render by chunk size. #14

0.6.1

Patches

  • Fix tree-map error deps.

0.6.0

Improve & Features

  • Support summary option details see #10.

credits

@a3mitskevich

0.5.0

Imporve & Features

  • Remove unnecessary assets or chunk info.
  • parsed and gzip size closer to the actual size.
  • Modify the data struct for stats.json.
  • Full details see #9.

0.4.0

Improve

  • Reduce package size.(Three quarters).

0.3.0

Features

  • Client Add Search function. #6

credits

@a3mitskevich

0.2.0

Improve & Features

  • Client Add Filter by entrypoints.
  • Perf client side-bar styles.

Minor

  • Changed output target to build.outDir by default.

Credits

@a3mitskevich @nonzzz

0.1.0

Imrpove & Features

This version is a stable version that implements most of the functions of webpack-bundle-analyzer. Provide a more streamlined configuration.

0.0.1

First version.