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.
- Host: GitHub
- URL: https://github.com/manferlo81/rollup-plugin-strip-shebang
- Owner: manferlo81
- License: mit
- Created: 2019-03-16T08:40:49.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2025-03-13T09:11:29.000Z (2 months ago)
- Last Synced: 2025-03-13T10:23:18.410Z (2 months ago)
- Topics: extract, hashbang, plugin, rollup, rollup-plugin, shebang, strip
- Language: TypeScript
- Size: 2.58 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# rollup-plugin-strip-shebang
[](https://circleci.com/gh/manferlo81/rollup-plugin-strip-shebang)
[](https://www.npmjs.com/package/rollup-plugin-strip-shebang)
[](https://codecov.io/gh/manferlo81/rollup-plugin-strip-shebang)
[](https://packagephobia.now.sh/result?p=rollup-plugin-strip-shebang)
[](https://bundlephobia.com/result?p=rollup-plugin-strip-shebang)
[](https://github.com/microsoft/typescript)
[](https://snyk.io/test/github/manferlo81/rollup-plugin-strip-shebang?targetFile=package.json)
[](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 nodeconsole.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)