GithubHelp home page GithubHelp logo

trysound / rollup-plugin-size-snapshot Goto Github PK

View Code? Open in Web Editor NEW
162.0 5.0 14.0 1.2 MB

Track your library bundles size and its treeshakability with less effort

License: MIT License

JavaScript 100.00%

rollup-plugin-size-snapshot's Introduction

rollup-plugin-size-snapshot Build Status

This plugin provides details about

  • actual bundle size (bundler parsing size)
  • minified bundle size (browser parsing size)
  • gzipped bundle size (download size)

All of these sizes are important criteria when choosing a library, and they will be stored in the .size-snapshot.json file.

There is also a nice feature for the es output format which provides sizes of treeshaked bundles with both rollup and webpack, so if your library has more than one independent parts, you can track that users will not consume dead code. Such bundles entry point looks like this

// nothing is imported here so nothing should go in user bundle
import {} from "library";

Why bundle with rollup

  • internals are hidden so you shouldn't worry that user reuses your frequently updated modules
  • faster user bundling if library has a lot of modules
  • predictable and more efficient scope hoisting and as a result more predictable size
  • easier to work without sourcemaps with vendors since development bundlers add a lot of unreadable stuff in module definition

Usage

import { sizeSnapshot } from "rollup-plugin-size-snapshot";

export default {
  input: "src/index.js",
  output: {
    file: "dist/index.js",
    format: "es",
  },
  plugins: [sizeSnapshot()],
};

If you use uglify or terser plugins, then make sure they are placed after this one.

import { uglify } from "rollup-plugin-uglify";
// or import { terser } from "rollup-plugin-terser";
import { sizeSnapshot } from "rollup-plugin-size-snapshot";

export default {
  // ...
  plugins: [sizeSnapshot(), uglify({ toplevel: true })],
};

Options

snapshotPath

type: string
default: '.size-snapshot.json'

matchSnapshot

This option allows you to verify that contributors don't forget to build or commit the .size-snapshot.json file. If this is true, the plugin will validate the snapshot against an existing one. Typically, one would define this option's value as true during continuous integration; using it locally is unintended.

type: boolean
default: false

threshold

Possible difference between sizes in actual snapshot and generated one.

Note: Make sense only when matchSnapshot is true.

type: number
default: 0

printInfo

Allows you to disable log to terminal.

type: boolean
default: true

License

MIT © Bogdan Chadkin

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.