Skip to content

rollup-plugin-replace-shebang在打包文件中保留 Shebang

一个 Rollup 插件,用于保留 shebang 并将其添加到输出文件顶部

rollup-plugin-replace-shebang

快速开始

安装

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

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

使用

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  // 设置输出文件可执行权限
    })
  ]
}

为什么选择 rollup-plugin-replace-shebang?

  • 自动保留:无需手动添加 shebang 到输出文件
  • 全版本兼容:支持 Rollup 2.x、3.x 和 4.x
  • 模板变量:在自定义 shebang 中使用 ${name}${version}
  • 文件模式支持:使用 glob 模式包含/排除特定文件
  • 可执行权限:可选设置 chmod +x 到输出文件

基于 MIT 许可发布