is there any way to make Webpack keep the #!/usr/bin/env node
at the top of my file?
I'm trying to bundle a CLI along with a module... it was a bit tricky to export my index.js / cli.js
separately using just one configuration file... and making the cli require index... i got it working...
However.. i didn't find any way to keep the #!/usr/bin/env node
at the top of my cli file, any ideas?
in shorts webpack outputs an file like this:
/******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; ..............................................................
but what i need is
#!/usr/bin/env node //<------ HEREEEE /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; ..............................................................
Webpack is a module bundler. It takes disparate dependencies, creates modules for them and bundles the entire network up into manageable output files. This is especially useful for Single Page Applications (SPAs), which is the defacto standard for Web Applications today.
Should I Use Webpack? If you're building a complex Front End™ application with many non-code static assets such as CSS, images, fonts, etc, then yes, Webpack will give you great benefits.
Webpack is first and foremost a bundler. Webpack's base functionality is to take a JavaScript file, resolve any dependencies ( require() , import , etc.), and output a bundled JavaScript file that contains all those dependencies. You can then run the bundled file without having to load those dependencies again.
Why to use webpack on node backend. If we are talking about react and node app you can build isomorphic react app. And if you are using import ES6 Modules in react app on client side it's ok - they are bundled by webpack on the client side.
You should be able to use BannerPlugin with raw mode for this. With this plugin you can add any string you want at the top of your bundle. By using the raw mode, it will not wrap the string in a comment.
In your webpack.config.js
file:
plugins: [ new webpack.BannerPlugin({ banner: "#!/usr/bin/env node", raw: true }), ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With