webpack打包含dll的electron项目配置

electron 调用 dll ,webpack的配置

  //重点配置项
  module.exports = {
  output: {
      libraryTarget: 'commonjs2',
    },
  //预加载 node electron
    externalsPresets: {
      node: true,
      electron: true,
      electronRenderer: true,
      electronMain: true
    },
    //外部模块
    externals: ['ffi-napi', 'ref-napi', 'ref-array-napi', 'ref-struct-napi'],
}

特别说明

webpack打包模块中__dirname获取不到怎么办? 改用 process.cwd()。

//render.js
const path = require('path');
const ffi = require('ffi-napi');
const ref = require('ref-napi');
//dll路径
let libpath = path.join(process.cwd(), '/native/ControlCAN.dll');
//加载dll
let testLib = ffi.Library(libpath, {
  VCI_OpenDevice: ['UInt32', ['UInt32', 'UInt32', 'UInt32']]
});

参考网址:
https://blog.csdn.net/zxl761303248/article/details/108051680

上一篇:Electron调用C++ DLL文件


下一篇:Dart 2.12 现已发布