From 675dcdc79cc009f4800971b9683473842deafe72 Mon Sep 17 00:00:00 2001 From: Andrew Carpenter Date: Thu, 7 Jun 2018 20:06:08 -0400 Subject: [PATCH] Update from rollup-analyzer to rollup-plugin-analyzer --- README.md | 106 +++++++++++++++++++++++++++------------------------ index.js | 2 +- module.js | 2 +- package.json | 17 +++++---- 4 files changed, 68 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 07965df..17d05e9 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,59 @@ -# rollup-analyzer [![NPM version](https://badge.fury.io/js/rollup-analyzer.svg)](https://npmjs.org/package/rollup-analyzer) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) [![Dependency Status](https://dependencyci.com/github/doesdev/rollup-analyzer/badge)](https://dependencyci.com/github/doesdev/rollup-analyzer) [![Build Status](https://travis-ci.com/doesdev/rollup-analyzer.svg)](https://travis-ci.com/doesdev/rollup-analyzer) +# rollup-plugin-analyzer [![NPM version](https://badge.fury.io/js/rollup-plugin-analyzer.svg)](https://npmjs.org/package/rollup-plugin-analyzer) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) [![Dependency Status](https://dependencyci.com/github/doesdev/rollup-plugin-analyzer/badge)](https://dependencyci.com/github/doesdev/rollup-plugin-analyzer) [![Build Status](https://travis-ci.com/doesdev/rollup-plugin-analyzer.svg)](https://travis-ci.com/doesdev/rollup-plugin-analyzer) -> Analyze file sizes of rollup bundled imports +> Mad metrics for your rollup bundles, know all the things -## rollup-analyzer +## rollup-plugin-analyzer -Rollup Analyzer gives you a quick look at what's taking up space in your bundle. +See what's bloating your bundle, how treeshaking has treated you, and other +great stuff. Perfect for console printing an analysis of your bundle or +integrating in your CI workflows. -### Comes in three scrumptious flavors: +### Comes in two scrumptious flavors: -#### [rollup-analyzer-plugin](https://github.com/doesdev/rollup-analyzer-plugin) -Adding as a plugin to your rollup config or build script will print a well -formatted analysis to the console upon bundling. +#### [rollup-plugin-analyzer](https://github.com/doesdev/rollup-plugin-analyzer) +Adding as a plugin to your rollup config or build script will allow you to +print a well formatted analysis to the console upon bundling or get a full +analysis object for CI purposes. -#### [rollup-analyzer-config](https://github.com/doesdev/rollup-analyzer-config) -If using Rollup's CLI to bundle with no additonal config, pass -`-c node:rollup-analyzer-config` to print a well formatted analysis to your console. - -#### [rollup-analyzer](https://github.com/doesdev/rollup-analyzer) -Full analysis module, giving you access to the complete analysis object or well -formatted analysis text for CI and build usage. +#### [rollup-config-analyzer](https://github.com/doesdev/rollup-config-analyzer) +If using Rollup's CLI to bundle with no additional config, pass +`-c node:rollup-config-analyzer` to print a well formatted analysis to your console. ## Install ```sh -$ npm install --save-dev rollup-analyzer +$ npm install --save-dev rollup-plugin-analyzer ``` ## Usage +### from rollup config +```js +import { plugin as analyze } from 'rollup-analyzer-plugin' +const opts = {limit: 5, filter: [], root: __dirname} +export default { + entry: 'module.js', + dest: 'index.js', + format: 'cjs', + plugins: [analyze(opts)] +} +``` + +### from build script ```js import { rollup } from 'rollup' -const { formatted } from 'rollup-analyzer' +import { plugin as analyze } from 'rollup-analyzer-plugin' +const opts = {limit: 5, filter: [], root: __dirname} -rollup({/*...*/}).then((bundle) => { - // print console optimized analysis string - formatted(bundle, {limit: 5}).then(console.log).catch(console.error) -}) +rollup({ + entry: 'main.js', + plugins: [analyze(opts)] +}).then(...) +``` -// Results in ... -/* +### results +logged to console on rollup completion +```sh ----------------------------- Rollup File Analysis ----------------------------- @@ -56,24 +71,28 @@ percent: 3.03% dependents: 1 - \app\helpers\transformer.js ... -*/ ``` -## API +## Options + +- **stdout** - *optional* + - type: Boolean + - default: `false` + - description: Print to stdout (console.log) instead of stderr (console.error) +- **limit** - *optional* + - type: Number + - default: `null` + - description: Limit number of files to output analysis of, sorted by DESC size +- **filter** - *optional* + - type: Array | String + - default: `null` + - description: Filter to only show imports matching the specified name(s) +- **root** - *optional* + - type: String + - default: `process.cwd()` + - description: Application directory, used to display file paths relatively -Module exports `analyze`, `formatted`, and `plugin` functions - -### formatted(bundle, options) -- arguments - - **bundle** *(Rollup Bundle)* - - **options** *(Object - see below for available options)* -- returns - - **analysisText** *(String - well formatted for console printing)* -### analyze(bundle, options) -- arguments - - **bundle** *(Rollup Bundle)* - - **options** *(Object - see below for available options)* - returns - **analysis** *(Object)* - **id** *(String)* - path of module / rollup module id @@ -81,19 +100,6 @@ Module exports `analyze`, `formatted`, and `plugin` functions - **dependents** *(Array)* - list of dependent module ids / paths - **percent** *(Number)* - percentage of module size relative to entire bundle -#### options `Object` - - **limit** - *optional* - - type: Number - - default: `null` - - description: Limit number of files to output analysis of, sorted by DESC size - - **filter** - *optional* - - type: Array | String - - default: `null` - - description: Filter to only show imports matching the specified name(s) - - **root** - *optional* - - type: String - - default: `process.cwd()` - - description: Application directory, used to display file paths relatively ## License diff --git a/index.js b/index.js index 2eaf6ee..9eaf6ba 100644 --- a/index.js +++ b/index.js @@ -103,7 +103,7 @@ const plugin = (opts = {}) => { return analyze({modules}, opts, !opts.onAnalysis).then(cb) }); return { - name: 'rollup-analyzer-plugin', + name: 'rollup-plugin-analyzer', transformChunk: (_a, _b, chunk) => new Promise((resolve, reject) => { resolve(null); if (!chunk || !chunk.orderedModules) return diff --git a/module.js b/module.js index b99a126..f18a0cb 100644 --- a/module.js +++ b/module.js @@ -101,7 +101,7 @@ export const plugin = (opts = {}) => { return analyze({modules}, opts, !opts.onAnalysis).then(cb) }) return { - name: 'rollup-analyzer-plugin', + name: 'rollup-plugin-analyzer', transformChunk: (_a, _b, chunk) => new Promise((resolve, reject) => { resolve(null) if (!chunk || !chunk.orderedModules) return diff --git a/package.json b/package.json index 28e4956..46addcc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "rollup-analyzer", - "version": "2.0.0-beta.3", - "description": "Analyze file sizes of rollup bundled imports", + "name": "rollup-plugin-analyzer", + "version": "2.0.0", + "description": "Mad metrics for your rollup bundles, know all the things", "main": "index.js", "module": "module.js", "files": [ @@ -14,14 +14,17 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/doesdev/rollup-analyzer.git" + "url": "git+https://github.com/doesdev/rollup-plugin-analyzer.git" }, "keywords": [ "rollup", + "plugin", "import", "bundle", "file", "size", + "treeshaking", + "metrics", "analysis", "analyze", "bloat" @@ -29,13 +32,13 @@ "author": "Andrew Carpenter (https://github.com/doesdev)", "license": "MIT", "bugs": { - "url": "https://github.com/doesdev/rollup-analyzer/issues" + "url": "https://github.com/doesdev/rollup-plugin-analyzer/issues" }, - "homepage": "https://github.com/doesdev/rollup-analyzer#readme", + "homepage": "https://github.com/doesdev/rollup-plugin-analyzer#readme", "devDependencies": { "ava": "^0.25.0", "husky": "^0.14.3", - "rollup": "^0.60.1", + "rollup": "latest", "rollup40": "npm:rollup@0.40.x", "rollup45": "npm:rollup@0.45.x", "rollup50": "npm:rollup@0.50.x",