koffi中文
  • KOFFI
  • koffi性能
  • 中文更新日志
  • 安装需求
  • 开始使用
  • 函数调用
  • 输入参数
  • 数据指针
  • 输出参数
  • 多态参数
  • Union数据
  • 导出的变量
  • JAVASCRIPT 回调
  • 杂项
  • 构建工具和koffi
  • 贡献
  • 变更日志
  • 迁移指南
Powered by GitBook
On this page
  • 构建工具
  • 本机模块
  • 间接加载
  • 打包示例
  • Electron with electron-builder#
  • Electron Forge
  • NW.js
  • Node.js and esbuild

构建工具和koffi

构建工具

本机模块

Koffi 2.5.9 中的简化

Koffi 使用本机模块来工作。NPM 包包含适用于各种平台和架构的二进制文件,并在运行时选择适当的模块。

理论上,构建工具应该能够找到所有本机模块,因为它们在 Javascript 文件中明确列出(作为静态字符串)并以某种方式打包它们。

如果不是这种情况,您可以手动安排复制node_modules/koffi/build/koffi构建脚本旁边的目录。

这是一个可行的示例:

koffi/
    win32_x64/
        koffi.node
    linux_x64/
        koffi.node
    ...
MyBundle.js

当在Electron中运行时,Koffi也会尝试在process.resourcesPath中查找本地模块。对于Electron应用程序,您可以像这样做。

locales/
resources/
    koffi/
        win32_ia32/
            koffi.node
        win32_x64/
            koffi.node
        ...
MyApp.exe

间接加载

Koffi 2.6.2 中的新功能

某些构建工具(例如 vite)不喜欢将 require 与本机模块一起使用。

在这种情况下,您可以使用require('koffi/indirect'),但需要确保原生 Koffi 模块已正确打包。

打包示例

Packaging with electron-builder should work as-is.

Electron Forge

Packaging with Electron Force should work as-is, even when using webpack as configured initially when you run:

npm init electron-app@latest my-app -- --template=webpack

NW.js

Packagers such as nw-builder should work as-is.

Node.js and esbuild

You can easily tell esbuild to copy the native files with the copy loader and things should just work. Use something like:

1esbuild index.js --platform=node --bundle --loader:.node=copy --outdir=dist/

Previous杂项Next贡献

Last updated 1 year ago

Electron with electron-builder

Take a look at the full .

Take a look at the full .

You can find a full .

You can find a full .

#
working example in the repository
working example in the repository
working example in the repository
working example in the repository