shebang2-loader
v1.0.1
Published
A simple Webpack loader for files starting with a shebang (usually #!/usr/bin/env node)
Downloads
16,303
Maintainers
Readme
shebang2-loader
This is an alternative Webpack loader for Unix-style shebangs (usually #!/usr/bin/env node
). It is meant to replace the
shebang-loader, which appears to be unmaintained and does not have proper
support for source maps.
Usage
Make this package available to Webpack:
npm i -D shebang2-loader
or
yarn add -D shebang2-loader
Configure the loader in your
webpack.config.js
.module: { rules: [ // ... { test: /example\/index.js$/, loader: "shebang2-loader" }, ] }
Make sure to place
shebang2-loader
as the last rule in the list of rules, so that Webpack will process it first.Here's a full example using Webpack's BannerPlugin to re-generate the shebang for a CLI application.
const webpack = require("webpack"); const path = require("path"); module.exports = { target: 'node', mode: 'development', entry: './main.js', output: { filename: 'dist.js', path: path.resolve(__dirname), }, plugins: [ new webpack.BannerPlugin({ banner: '#!/usr/bin/env node', raw: true }), ], devtool: 'source-map', module: { rules: [ { test: /\.m?js$/, exclude: /node_modules/, loader: 'babel-loader' }, { test: /example\/index.js$/, loader: "shebang2-loader" }, ] } };
Run Webpack as you'd usually do.
webpack --watch --config webpack.config.js
License
This software is licensed under the MIT license.