Gathering detailed insights and metrics for webpack-shebang-plugin
Gathering detailed insights and metrics for webpack-shebang-plugin
Gathering detailed insights and metrics for webpack-shebang-plugin
Gathering detailed insights and metrics for webpack-shebang-plugin
The official repository of https://www.npmjs.com/package/webpack-shebang-plugin
npm install webpack-shebang-plugin
Typescript
Module System
76.7
Supply Chain
99.4
Quality
75.9
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
586,111
Last Day
63
Last Week
1,279
Last Month
5,709
Last Year
107,294
MIT License
2 Stars
18 Commits
1 Watchers
20 Branches
1 Contributors
Updated on May 22, 2025
Minified
Minified + Gzipped
Latest Version
1.1.8
Package Id
webpack-shebang-plugin@1.1.8
Unpacked Size
10.43 kB
Size
3.81 kB
File Count
6
Cumulative downloads
Total Downloads
Last Day
10.5%
63
Compared to previous day
Last Week
-9.7%
1,279
Compared to previous week
Last Month
-33.2%
5,709
Compared to previous month
Last Year
-54.2%
107,294
Compared to previous year
No dependencies detected.
This is an all-in-one webpack plugin which prepends hashbangs automatically to the generated bundle files and make it executable -- all revived from your entry source file.
You can actually use this plugin to do anything that BannerPlugin is able to do, by changing the default pattern and the mark in your source files. Please see More Usage demo for more details.
This plugin embeds a simple loader which deals with the hashbang syntax OR any syntax you can specify as a regular expression. You don't need any other dependencies or libs, such as shebang-loader, BannerPlugin, nor do you need extra configurations.
webpack >= 4.0.0 is required.
In npm:
npm install -D webpack-shebang-plugin
Or in yarn:
yarn add -D webpack-shebang-plugin
1 2#!/usr/bin/env node 3 4// The first line is the shebang you want be added. 5// Don't worry about the spaces and line breaks around it. 6 7// You can add shebang mark anywhere in any source file, 8// but only if the first meaningful line of your entry file matches the pattern, 9// it will be regarded as the shebang and will be prepended to the output bundle, 10// all the other useless shebang marks will be removed in the output. 11console.log('this is your entry JS file.'); 12
1 2const ShebangPlugin = require('webpack-shebang-plugin'); 3 4// ...other webpack configuration 5 6plugins: [ 7 // ...other webpack plugins 8 9 new ShebangPlugin() 10 11 // ...other webpack plugins 12] 13 14// ...other webpack configuration
1#!/usr/bin/env node 2 3/******/ (() => { // webpackBootstrap 4/******/ var __webpack_modules__ = ({ 5/* 6 ...... generated code ...... 7 */
1new ShebangPlugin({ 2 // optional, you can specify a different regular expression here for your own pattern. 3 // the pattern below is used by default, if unset. It matches syntax like: 4 // #!........ 5 // The regular expression should contain a group of the main shebang part as $1, in the above case, 6 // the shebang part "#!........" will be grouped out. 7 // * If you create one of your own, you should keep sure that the main part will be grouped out as $1, 8 // and it will be used as your shebang. 9 // * If you are not sure how to write your regular expression, please just leave it unset. 10 shebangRegExp: /[\s\n\r]*(#!.*)[\s\n\r]*/gm, 11 12 // optional, you can specify r/w/e permissions in octal value. 13 // The default value is 0o755, which makes the output bundle executable. 14 // You can set the value to 0, if you want to keep the default permissions. 15 chmod: 0o755, 16})
Suppose you have two different entries, and you wish to have two output bundles:
1/*** 2This is my custom banner 3I want this block appear 4in my first bundle. 5***/ 6 7require('./required-by-entry1.js'); 8 9console.log('my first bundle');
1/*** 2This block also matches the 3custom banner pattern, but 4because this file is not the entry 5asset, so this block of content 6will be abandoned. 7***/ 8 9console.log('imported in first bundle');
1console.log('my second bundle');
1const path = require('path'); 2const ShebangPlugin = require('webpack-shebang-plugin'); 3 4module.exports = { 5 mode: 'production', 6 target: 'node', 7 entry: { 8 first: { 9 import: ['./src/entry1.js', './src/import-in-first-bundle.js'], 10 filename: 'bundle1.js' 11 }, 12 second: { 13 import: './src/entry2.js', 14 filename: 'bundle2.js' 15 }, 16 }, 17 output: { 18 path: path.resolve(__dirname, 'dist'), 19 filename: '[name].js' 20 }, 21 module: { 22 rules: [ 23 { 24 test: /\.js$/, 25 exclude: [ 26 /node_modules/ 27 ], 28 use: [ 29 { 30 loader: 'babel-loader' 31 } 32 ] 33 } 34 ] 35 }, 36 plugins: [ 37 new ShebangPlugin({ 38 shebangRegExp: /[\s\n\r]*(\/\*{3}[\s\S]*?\*{3}\/)[\s\n\r]*/gm 39 }) 40 ] 41}
1/*** 2This is my custom banner 3I want this block appear 4in my first bundle. 5***/ 6// entry1.js code here 7// import-in-first-bundle.js code here
1// entry2.js code here
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 0/12 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More