Skip to content

rollup-plugin-replace-shebangPreserve Shebang in Your Bundle

A Rollup plugin that preserves and relocates shebang (#!) to the output bundle

rollup-plugin-replace-shebang

Quick Start

Install

bash
# pnpm
pnpm add -D rollup-plugin-replace-shebang

# npm
npm install -D rollup-plugin-replace-shebang

Usage

js
import replaceShebang from 'rollup-plugin-replace-shebang'

export default {
  input: 'src/cli.js',
  output: {
    file: 'dist/cli.js',
    format: 'es'
  },
  plugins: [
    replaceShebang({
      chmod: true  // Make output executable
    })
  ]
}

Why rollup-plugin-replace-shebang?

  • Automatic Preservation: No need to manually add shebang to output files
  • Works with All Rollup Versions: Compatible with Rollup 2.x, 3.x, and 4.x
  • Template Variables: Use ${name} and ${version} in custom shebangs
  • File Pattern Support: Include/exclude specific files with glob patterns
  • Executable Permissions: Optionally set chmod +x on output files

Released under the MIT License.