1.0.1 • Published 5 years ago
shebang2-loader v1.0.1
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-loaderor
yarn add -D shebang2-loaderConfigure the loader in your
webpack.config.js.module: { rules: [ // ... { test: /example\/index.js$/, loader: "shebang2-loader" }, ] }Make sure to place
shebang2-loaderas 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.