是否可以在没有将节点集成设置为 true 的情况下访问电子应用程序中的节点?

Is it possible to access node in an electron app without node integration set to true?

我正在使用香草电子应用程序。 (npx create-electron-app ......)

可以用 nodeintegration:trueconst electron = require("electron"); 吗?

我使用的库不支持 nodeintegration:true,但我的脚本需要 nodeintegration:true 到 运行。

没有nodeintegration:true是否有另一种访问电子或节点的方法?

我觉得你不行
更好的选择是设置

options = {
    webPreferences: {
         contextIsolation: false, 
         nodeIntegration: true,
         preload: "preload.js" //keep in same path as app.js (or index.js, whatever you use)
    }
};

其中,options 是您在电子中创建 BrowserWindow 时使用的对象。

在 preload.js 中(我假设您想使用一个名为 glob 的库)

window.glob = require("glob");

现在,在 HTML 文件(前端)的任何位置,您都可以将库引用为 window.glob