Skip to content

Commit

Permalink
Update from rollup-analyzer to rollup-plugin-analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
doesdev committed Jun 8, 2018
1 parent 97b82d1 commit 675dcdc
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 59 deletions.
106 changes: 56 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
-----------------------------
Expand All @@ -56,44 +71,35 @@ 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
- **size** *(Number)* - size of module in bytes
- **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

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -14,28 +14,31 @@
},
"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"
],
"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",
Expand Down

0 comments on commit 675dcdc

Please sign in to comment.