A Rollup plugin that preserves and relocates shebang (#!) from entry files to the output bundle. Version 2.0.0, released with breaking changes in file paths (ESM: dist/index.mjs, CJS: dist/index.cjs, types: dist/index.d.mts and dist/index.d.cts). Supports include/exclude glob patterns, template variables in shebang (${name}, ${version}), chmod auto-set executable permissions, and skipBackslash option. Ships TypeScript types, requires Rollup >= 2.0.0 and Node >= 12. Differentiators: simple API, template variables, chmod support, and pattern filtering unlike alternative plugins.
npm install rollup-plugin-replace-shebangVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage: preserving a shebang from entry file to output bundle with options shebang, skipBackslash, and chmod.
Update your imports or references to use the new paths: import from 'dist/index.mjs' instead of 'es/index.mjs'.
Use import syntax instead of require(). If you must use CJS, consider using dynamic import or stick with v1.x.
Ensure package.json is accessible and contains correct name and version fields.
Only enable skipBackslash when you specifically need to preserve backslash encoded newlines in the shebang.
Use the 'chmod' option only on Unix-like systems or handle permission errors gracefully.
Use import syntax or convert your config to ESM (e.g., .mjs extension or type:module in package.json).
Use the default import: import replaceShebang from 'rollup-plugin-replace-shebang'
Run: npm install -D rollup-plugin-replace-shebang