Skip to content

Commit 6c78820

Browse files
committed
Start updating API in readme
1 parent 46c03cb commit 6c78820

1 file changed

Lines changed: 26 additions & 23 deletions

File tree

README.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ $ npm install --save-dev rollup-analyzer
2929
## Usage
3030

3131
```js
32-
const rollupAnalyzer = require('rollup-analyzer')({limit: 5})
33-
rollup.rollup({/*...*/}).then((bundle) => {
32+
import { rollup } from 'rollup'
33+
const { formatted } from 'rollup-analyzer'
34+
35+
rollup({/*...*/}).then((bundle) => {
3436
// print console optimized analysis string
35-
rollupAnalyzer.formatted(bundle).then(console.log).catch(console.error)
37+
formatted(bundle, {limit: 5}).then(console.log).catch(console.error)
3638
})
3739

3840
// Results in ...
@@ -59,12 +61,27 @@ dependents: 1
5961

6062
## API
6163

62-
### rollupAnalyzer
63-
the default exported function is identical to init, and returns the same functions as export {init, formatted, analyze}. So, you can `require('rollup-analyzer')` or `require('rollup-analyzer')({limit: 5})` and use the same functions.
64-
65-
### rollupAnalyzer.init(options)
66-
set options to use in analysis (this step is optional)
67-
- **options** *(Object)*
64+
Module exports `analyze`, `formatted`, and `plugin` functions
65+
66+
### formatted(bundle, options)
67+
- arguments
68+
- **bundle** *(Rollup Bundle)*
69+
- **options** *(Object - see below for available options)*
70+
- returns
71+
- **analysisText** *(String - well formatted for console printing)*
72+
73+
### analyze(bundle, options)
74+
- arguments
75+
- **bundle** *(Rollup Bundle)*
76+
- **options** *(Object - see below for available options)*
77+
- returns
78+
- **analysis** *(Object)*
79+
- **id** *(String)* - path of module / rollup module id
80+
- **size** *(Number)* - size of module in bytes
81+
- **dependents** *(Array)* - list of dependent module ids / paths
82+
- **percent** *(Number)* - percentage of module size relative to entire bundle
83+
84+
#### options `Object`
6885
- **limit** - *optional*
6986
- type: Number
7087
- default: `null`
@@ -78,20 +95,6 @@ set options to use in analysis (this step is optional)
7895
- default: `process.cwd()`
7996
- description: Application directory, used to display file paths relatively
8097

81-
### rollupAnalyzer.formatted(bundle)
82-
returns Promise which resolves with well formatted analysis string (for CLI printing)
83-
- **bundle** *(Rollup Bundle)* - *required*
84-
85-
### rollupAnalyzer.analyze(bundle)
86-
returns Promise which resolves with array of objects describing each imported file
87-
- **bundle** *(Rollup Bundle)* - *required*
88-
89-
returned array's child analysis objects have the following properties
90-
- **id** *(String)* - path of module / rollup module id
91-
- **size** *(Number)* - size of module in bytes
92-
- **dependents** *(Array)* - list of dependent module ids / paths
93-
- **percent** *(Number)* - percentage of module size relative to entire bundle
94-
9598
## License
9699

97100
MIT © [Andrew Carpenter](https://github.com/doesdev)

0 commit comments

Comments
 (0)