Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
exoego committed Apr 28, 2024
1 parent de64a54 commit a144b42
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 37 deletions.
55 changes: 19 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,51 @@ Analyzes each PR's impact on esbuild bundle size

## Usage

###
### Basic

```yaml
# Ensure you build your project before running this action
- name: Run esbuild
run: npm run build

# Call this action after the build
- name: Analyze esbuild bundle size
uses: exoego/esbuild-bundle-analyzer@main
with:
metafiles: "out/meta.json"
```
###
## Action inputs
### `metafiles (string)`

(Required) A comma-separated list of paths to [esbuild's meta file]([https://esbuild.github.io/api/#metafile]). Must be non-empty.

As of esbuild v0.20.0, you need to write the meta file by yourself after build, something like this:
As of esbuild v0.20.0, you need to [write
***meta file*** yourself after build](https://esbuild.github.io/api/#metafile), something like this:
```javascript
// esbuild.mjs
import * as esbuild from 'esbuild'
import fs from 'node:fs'

let result = await esbuild.build({
entryPoints: ['src/app1.js', 'src/app2.js'],
bundle: true,
metafile: true,
outdir: 'dist',
entryPoints: ['src/app1.ts', 'src/app2.ts'],
bundle: true,
metafile: true,
outdir: 'dist',
})

fs.writeFileSync('dist/meta.json', JSON.stringify(result.metafile))
```

In this case, the `metafiles` config should be `"dist/meta.json"`.

Typically, you only need one meta file since one meta file can contain multiple out files information.
Multiple meta files may be useful for more complex scenarios.
In this case, the `metafiles` input should be `"dist/meta.json"`.

### `analyze_directory (string)`
If you have multiple meta files, you can specify them like this `"dist/meta1.json,dist/meta2.json"`.

(Optional, defaults to `.analyzer`) If an out file size has increased more than this percent, display a "‼️" to draw attention
to the change.

### `budget_percent_increase_red (number)`

(Optional, defaults to `20`) If an out file size has increased more than this percent, display a "‼️" to draw attention
to the change.

### `showDetails (boolean)`

(Optional, defaults to `true`) This option renders a collapsed "details" section explaining some of the finer details of
the numbers provided and icons. If you feel like this is not necessary and you and/or those working on your project
understand the details, you can set this option to `false` and that section will not render.

### `skipCommentIfEmpty (boolean)`
## Action inputs

(Optional, defaults to `false`) When set to `true`, if no out files have changed size, the generated comment will be an
empty string.
Name | Default | Description
-------|---------|------------
`metafiles` | - | A required comma-separated list of paths to [esbuild's meta file]([https://esbuild.github.io/api/#metafile]).
`analyze_directory` | `.analyzer` | A path to working directory where bundle analysis are stored.
`budget_percent_increase_red` | `20` | If an out file size has increased more than this percent, display a "‼️" to draw extra attention to the change.
`show_details` | `true` | If `true`, a collapsed "details" section is rendered. It explains the details of the numbers provided and icons.
`skip_comment_if_empty` | `false` | If `true` and no out files have changed size, the generated comment will be an empty string.

## Action outputs

Expand Down
Loading

0 comments on commit a144b42

Please sign in to comment.