日々の実践 [サードパーティの静的ファイルをパッケージ化する NodeJs]

バックグラウンド:

特定のタスクを完了するために、サードパーティの実行可能ファイルを呼び出す必要がある場合があります。

これらのサードパーティの実行可能ファイルをローカルでコンパイルまたはインストールするには、時間と労力がかかります。

そこで、これらのサードパーティの実行可能ファイルによってパッケージ化された静的ファイルをライブラリに作成する操作があります。

このようにして、依存関係が 1 つインストールされている限り、これらのサードパーティの実行可能ファイルを呼び出すことができます。

//
// With credits to https://github.com/eugeneware/ffmpeg-static
//
var os = require('os');
var path = require('path');

var platform = os.platform();
if (platform !== 'darwin' && platform !=='linux' && platform !== 'win32') {
  console.error('Unsupported platform.');
  process.exit(1);
}

var arch = os.arch();
if (platform === 'darwin' && arch !== 'x64' && arch !== 'arm64') {
  console.error('Unsupported architecture.');
  process.exit(1);
}

var ffprobePath = path.join(
  __dirname,
  'bin',
  platform,
  arch,
  platform === 'win32' ? 'ffprobe.exe' : 'ffprobe'
);

exports.path = ffprobePath;

要点:

最初にシステムを判断し、次にプラットフォームを判断します。

フォールトトレランス。

おすすめ

転載: blog.csdn.net/u012787757/article/details/130380797
おすすめ