https://github.com/septh/rollup-plugin-code-raker
A Rollup plugin that rakes your bundle to remove dead leaves.
https://github.com/septh/rollup-plugin-code-raker
Last synced: 4 months ago
JSON representation
A Rollup plugin that rakes your bundle to remove dead leaves.
- Host: GitHub
- URL: https://github.com/septh/rollup-plugin-code-raker
- Owner: Septh
- Created: 2024-12-03T07:43:26.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-08-31T13:16:54.000Z (9 months ago)
- Last Synced: 2025-10-03T05:35:22.525Z (8 months ago)
- Language: TypeScript
- Size: 74.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README




# rollup-plugin-code-raker
> A Rollup/Vite plugin that rakes your bundle to remove dead leaves.
## Features
- Removes leftover comments, `console.*` calls and `debugger` statements from your bundle.
- Does not come in the way of treeshaking: remaining function annotations are removed *after* Rollup/Vite did their magic.
- Fully configurable.
- Comes with sensible defaults for both application and library bundling.
## Requirements
This plugin requires Rollup 4 or later or Vite 5 or later.
## Usage
Install the plugin using your favorite package manager:
```sh
npm install --save-dev rollup-plugin-code-raker
```
Then import the plugin in your `rollup.config.js`/`vite.config.js`:
```js
import rake from 'rollup-plugin-code-raker'
export default {
...
plugins: [
rake(/* options */)
]
}
```
## Options
code-raker uses *presets* to decide what to remove from code.
- The default preset is a "kill'em all" preset that blindly **removes** all comments (including licensing and documentation comments), all `console.*` calls and `debugger` statements.
- The `application` preset **preserves** licensing comments and `console.info`, `console.warn`, `console.error` and `console.debug` calls.
- The `library` preset **preserves** licensing and documentation comments.
> [!NOTE]
> - *Licensing* comments are block comments that start with `/*!` followed by a space or a newline, or documentation comments that contain the `@license` tag.
> - *Documentation*, or JsDoc/TsDoc comments, are block comments that start with `/**` followed by a space or a newline.
> - *Annotations* are block comments that contain one of these strings: `#__PURE__`, `@__PURE__`, `#__NO_SIDE_EFFECTS__`, `@__NO_SIDE_EFFECTS__`. See https://rollupjs.org/configuration-options/#treeshake-annotations for more info.
All options are optional.
```typescript
export interface Options {
/**
* The name of a preset to use or extend upon.
*
* Default: undefined.
*/
preset?: 'library' | 'application'
/**
* Set to `true` to remove all comments, `false` to remove none, or an object
* to only remove select comments.
*
* Default depends on the selected preset:
* - default: remove all comments.
* - library: preserve licensing and JsDoc/TsDoc comments, remove everything else.
* - application: preserve licensing comments, remove everything else.
*
* Note that this setting only targets "meaningful" comments; common block comments (`/*`)
* and line comments (`//`) are always removed.
*/
comments?: boolean | {
/**
* Whether to remove licensing comments.
*/
licenses?: boolean | ((comment: string) => boolean)
/**
* Whether to remove documentation comments.
*/
docs?: boolean | ((comment: string) => boolean)
/**
* Whether to remove annotations.
*/
annotations?: boolean
}
/**
* Set to `true` to remove all `console` calls, `false` to remove none, or a callback
* or an object to only remove select `console` calls.
*
* Default depends on the selected preset:
* - default: remove all `console` methods calls.
* - library: remove all `console` methods calls.
* - application: preserve `info`, `warn`, `error` and `debug` methods calls,
* remove all others.
*/
console?: boolean | ((method: string, statement: string) => boolean) | {
/**
* An array of console methods names to remove.
*/
include?: string[]
/**
* An array of console methods names to preserve.
*/
exclude?: string[]
}
/**
* Set to `true` to remove `debugger` statements, or `false` to leave them in code.
*
* Default: `true` in all presets.
*/
debugger?: boolean
}
```
## License
MIT.