An open API service indexing awesome lists of open source software.

https://github.com/manferlo81/rollup-plugin-strip-shebang

A Rollup.js plugin to remove and optionally extract shebang.
https://github.com/manferlo81/rollup-plugin-strip-shebang

extract hashbang plugin rollup rollup-plugin shebang strip

Last synced: about 1 month ago
JSON representation

A Rollup.js plugin to remove and optionally extract shebang.

Awesome Lists containing this project

README

        

# rollup-plugin-strip-shebang

[![CircleCI](https://circleci.com/gh/manferlo81/rollup-plugin-strip-shebang.svg?style=svg)](https://circleci.com/gh/manferlo81/rollup-plugin-strip-shebang)
[![npm](https://badgen.net/npm/v/rollup-plugin-strip-shebang)](https://www.npmjs.com/package/rollup-plugin-strip-shebang)
[![codecov](https://codecov.io/gh/manferlo81/rollup-plugin-strip-shebang/branch/main/graph/badge.svg)](https://codecov.io/gh/manferlo81/rollup-plugin-strip-shebang)
[![packagephobia](https://badgen.net/packagephobia/install/rollup-plugin-strip-shebang)](https://packagephobia.now.sh/result?p=rollup-plugin-strip-shebang)
[![bundlephobia](https://badgen.net/bundlephobia/min/rollup-plugin-strip-shebang)](https://bundlephobia.com/result?p=rollup-plugin-strip-shebang)
[![types](https://img.shields.io/npm/types/rollup-plugin-strip-shebang.svg)](https://github.com/microsoft/typescript)
[![Known Vulnerabilities](https://snyk.io/test/github/manferlo81/rollup-plugin-strip-shebang/badge.svg?targetFile=package.json)](https://snyk.io/test/github/manferlo81/rollup-plugin-strip-shebang?targetFile=package.json)
[![license](https://badgen.net/github/license/manferlo81/rollup-plugin-strip-shebang)](LICENSE)

A [Rollup.js](https://github.com/rollup/rollup) plugin to remove and optionally extract shebang.

## DEPRECATION NOTICE

As of Rollup v3 shebang will be stripped by rollup itself, but you might still need this plugin if you need to capture the shebang in order to add it back later.

As of [Rollup v4](https://github.com/rollup/rollup/blob/master/CHANGELOG.md#400) shebang will be stripped out and added back into the output file ([check it out here](https://github.com/rollup/rollup/pull/5163)), making this plugin almost unnecessary.

## Install

```bash
npm i rollup-plugin-strip-shebang
```

## Usage

```javascript
// example.js
#!/usr/bin/env node

console.log("Hi!");
```

```javascript
// rollup.config.js
import { stripShebang } from "rollup-plugin-strip-shebang";

export default {

input: "example.js",

output: {
file: "bin/cli.js",
format: "cjs"
},

plugins: [
stripShebang()
]

};
```

## Features

* Target file filtering *(see [include / exclude](#include--exclude-options))*
* Capture stripped shebang *(see [capture](#capture-option) option)*
* Sourcemap support *(see [sourcemap](#sourcemap-option) option)*

## Options

### `include` / `exclude` options

[minimatch](https://github.com/isaacs/minimatch) pattern to be used as filter, see `createFilter` [documentation](https://github.com/rollup/rollup-pluginutils#createfilter).

***syntax***

```typescript
include: Array | string | RegExp | null;
exclude: Array | string | RegExp | null;
```

### `capture` option

You can pass a capture `function` or `object` to get the stripped shebang in case you need it later.

#### `capture` option as `function`

***syntax***

```typescript
capture: (shebang: string) => void;
```

***example***

```javascript
let shebang;
...
plugins: [
strip({
capture(capturedShebang) {
shebang = capturedShebang;
},
}),
]
...
console.log(shebang);
```

#### `capture` option as `object`

***syntax***

```typescript
capture: Object;
```

***example***

```javascript
let capture = {};
...
plugins: [
strip({
capture,
}),
]
...
console.log(capture.shebang);
```

### `sourcemap` option

You can pass `sourcemap: false` to speed things up a bit if you don't need source maps. Anything other than `false` will default to `true`, including `null` and `undefined`.

***syntax***

```typescript
sourcemap: boolean = true;
```

***example***

```javascript
...
output: {
file: "bin/lib.js",
sourcemap: false,
},
plugins: [
strip({
sourcemap: false,
}),
]
...
```

> :warning: *Note that you will get a warning if you set rollup to generate source maps and set this to* `false`*.*

## License

[MIT](LICENSE) © 2019-2024 [Manuel Fernández](https://github.com/manferlo81)