Search code examples
webpackelectronexecutableelectron-forge

webpack - How to bundle binaries with executable file permissions


I'm on Linux and I need to bundle ffmpeg in my electron + webpack project. Currently, the ffmpeg executable gets bundled like this:

.webpack
├── main
│   ├── assets
│   │   ...
│   ├── index.js
│   ├── index.js.map
│   └── native_modules
│       ├── ffmpeg
│       ├── ffprobe
│       ├── linux-x64
│       │   ├── ffmpeg
│       │   └── package.json
│       ├── package.json
│       └── presets
│           ...
└── renderer
    ...

The executables are bundled with the app, however, they are not in executable mode.

So far, I used a workaround, where I would change the file modes of the binaries in my app on launch, but that doesn't work when deploying as an AppImage.

So my question is, how can I tell webpack to bundle these files as executable binaries?


Solution

  • I managed to get it working using the webpack-shell-plugin-next. In webpack.main.config.js:

    const WebpackShellPluginNext = require('webpack-shell-plugin-next');
    
    module.exports = {
      // ...
      plugins: [
        // ...
        new WebpackShellPluginNext({
          onBuildEnd: {
            scripts: [
              'chmod +x .webpack/main/native_modules/ffmpeg',
              'chmod +x .webpack/main/native_modules/ffprobe',
            ],
            blocking: false,
            parallel: true
          }
      ],
      // ...
    }