如何保持使用webpack我的shebang?

有什么办法让Webpack把#!/usr/bin/env node在我的文件的顶部?

我试图捆绑CLI和一个模块…这是一个有点棘手导出我的index.js / cli.js分别使用一个configuration文件…并使cli需要索引…我得到它工作…

但是..我没有find任何方法来保持#!/usr/bin/env node在我的cli文件的顶部,任何想法?

简而言之,webpack会输出一个像这样的文件:

 /******/ (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 。 有了这个插件,你可以在你的包的顶部添加你想要的任何string。 通过使用原始模式,它不会将string包装在注释中。

在你的webpack.config.js文件中:

 plugins: [ new webpack.BannerPlugin('#!/usr/bin/env node', { raw: true }); ]