有什么方法可以让 Webpack 将 #!/usr/bin/env 节点 保留在我的文件顶部?
is there any way to make Webpack keep the #!/usr/bin/env node at the top of my file?
我正在尝试将 CLI 与模块捆绑在一起……仅使用一个配置文件单独导出我的 index.js/cli.js 有点棘手……并且使 cli 需要索引...我得到了它的工作...
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...
但是..我没有找到任何方法将 #!/usr/bin/env node 保留在我的 cli 文件的顶部,有什么想法吗?
However.. i didn't find any way to keep the #!/usr/bin/env node at the top of my cli file, any ideas?
简而言之,webpack 输出这样的文件:
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; ..............................................................但我需要的是
#!/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; .............................................................. 推荐答案你应该能够使用 BannerPlugin 为此使用原始模式.使用此插件,您可以在包的顶部添加您想要的任何字符串.通过使用原始模式,它不会将字符串包装在注释中.
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.
在你的 webpack.config.js 文件中:
plugins: [ new webpack.BannerPlugin({ banner: "#!/usr/bin/env node", raw: true }), ]更多推荐
如何使用 webpack 保持我的shebang?
发布评论