Skip to content

Examples

This section contains example projects demonstrating how to use rollup-plugin-replace-shebang with different Rollup versions.

Online Examples

Try the plugin online with StackBlitz:

ExampleDescriptionLink
Rollup v2Rollup 2.x with custom shebang, template variables, and Plugin APIOpen in StackBlitz
Rollup v4Rollup 4.x with all features including skipBackslashOpen in StackBlitz

Local Examples

Clone the repository and try the examples locally:

bash
git clone https://github.com/saqqdy/rollup-plugin-replace-shebang.git
cd rollup-plugin-replace-shebang/examples/rollup-v4
pnpm install
pnpm run build
./dist/cli.js info

Feature Coverage

Featurerollup-v2rollup-v4
Basic shebang
Custom shebang-
Template variables (${name}, ${version})-
chmod
include-
exclude-
warnOnMultiple-
skipBackslash-
preserve✓ (commented)-
Plugin API

Pattern Matching

The plugin supports various glob patterns for include and exclude:

PatternExampleMatches
Exact matchsrc/cli.tsOnly src/cli.ts
Extension match**/*.tsAny .ts file
Prefix matchsrc/**Any file under src/
Directory match**/node_modules/**Any file in node_modules
Wildcard matchsrc/*.test.tssrc/foo.test.ts only
Plain stringnode_modulesAny path containing node_modules

Plugin API Usage

The plugin exposes an API for accessing shebang information:

js
const plugin = replaceShebang({ /* options */ })

// After transform phase, access shebang info
plugin.api.getShebang('/path/to/file.js')  // Returns shebang string or undefined
plugin.api.getAllShebangs()                  // Returns Map<string, ModuleInfo>

Released under the MIT License.