13
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

electron builderでバイナリを組み込む

Posted at

前提

  • Electronでバイナリを組み込んでspawnやexecで実行してる
  • Electron Builderを使っている

問題

  • バイナリをアプリ内に組み込む必要
  • バイナリのパスを解決する必要

解決

以下のissueが参考になる。
https://github.com/electron-userland/electron-builder/issues/751

最後の方のコメントにあるようにextraResourcesの指定とNODE_ENVによるバイナリパスの分岐をする。

1.app/bin/some_cmdにバイナリ配置
2.package.jsonのbuild.extraResoucesに以下のように指定

{
  "build": {
    "extraResources": [
      "app/bin/"
    ],
    //...
  }
}

3.NODE_ENVで分岐

app/src/main/index.js
const cmd = process.env.NODE_ENV === 'development'
  ? path.join(__dirname, '../../bin/some_cmd')
  : path.join(process.resourcesPath, 'app/bin/some_cmd')
13
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?