在一个简单的 Typescript 程序中,我require
使用 Node FFI
import * as Electron from 'electron';`
import * as ffi from 'ffi';`
进而
mylib = ffi.Library('libmoi', {
'worker': [ 'string', [ 'string' ] ],
'test' : [ 'string', [] ]
} );
通过 webpack 将其链接起来
WARNING in ./~/bindings/bindings.js
Critical dependencies:
76:22-40 the request of a dependency is an expression
76:43-53 the request of a dependency is an expression
@ ./~/bindings/bindings.js 76:22-40 76:43-53
问题似乎是 FFI 具有动态性require
,并且修复似乎是webpack.ContextReplacementPlugin
在webpack.config.js
文件中应用。
这有点超出我的能力范围,但 Angular 案例的一个例子是:
plugins: [
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
root('./src') // location of your src
)
]
知道如何为 FFI 执行此操作吗?