Skip to content

manferlo81/rollup-plugin-strip-shebang

Repository files navigation

rollup-plugin-strip-shebang

CircleCI npm codecov packagephobia bundlephobia types Known Vulnerabilities license

A Rollup.js 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 shebang will be stripped out and added back into the output file (check it out here), making this plugin almost unnecessary.

Install

npm i rollup-plugin-strip-shebang

Usage

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

console.log("Hi!");
// 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

Options

include / exclude options

minimatch pattern to be used as filter, see createFilter documentation.

syntax

include: Array<string | RegExp> | string | RegExp | null;
exclude: Array<string | RegExp> | 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

capture: (shebang: string) => void;

example

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

capture option as object

syntax

capture: Object;

example

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

sourcemap: boolean = true;

example

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

⚠️ Note that you will get a warning if you set rollup to generate source maps and set this to false.

License

MIT © 2019-2024 Manuel Fernández

About

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

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •