Skip to content

Options

shebang

  • Type: string
  • Default: Original shebang from source file

Custom shebang to prepend to the output bundle.

js
replaceShebang({
  shebang: '#!/usr/bin/env node'
})

Template Variables

The shebang option supports template variables that are automatically replaced:

js
replaceShebang({
  shebang: '#!/usr/bin/env node # ${name} v${version}'
})
// Output: #!/usr/bin/env node # my-cli v1.0.0
VariableDescription
${name}Package name from package.json
${version}Package version from package.json

skipBackslash

  • Type: boolean
  • Default: false

Preserve \u005c escape sequences in the output.

js
replaceShebang({
  skipBackslash: true
})

This is useful when your code contains backslash escape sequences that should be preserved.


preserve

  • Type: boolean
  • Default: false

Preserve the original shebang without modification.

js
replaceShebang({
  preserve: true
})

When enabled, the plugin will use the exact shebang from the source file, ignoring any custom shebang option.


chmod

  • Type: boolean
  • Default: false

Automatically set executable permission (chmod +x) on output files.

js
replaceShebang({
  chmod: true
})

This makes the output file directly executable on Unix-like systems.


include

  • Type: string | string[]
  • Default: ['**/*.js', '**/*.ts', '**/*.mjs', '**/*.cjs', '**/*.jsx', '**/*.tsx']

Files to include for shebang processing.

js
replaceShebang({
  include: ['src/cli.ts', 'src/bin/*.ts']
})

Supported Patterns

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

exclude

  • Type: string | string[]
  • Default: ['node_modules/**']

Files to exclude from shebang processing.

js
replaceShebang({
  exclude: ['node_modules/**', '**/*.test.ts']
})

Supports the same pattern types as include.


warnOnMultiple

  • Type: boolean
  • Default: true

Warn when multiple files have shebangs.

js
replaceShebang({
  warnOnMultiple: false  // Disable warning
})

When building multiple entry points, the plugin will warn if more than one file contains a shebang, as typically only the main entry point should have one.

Released under the MIT License.