简体   繁体   English

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

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

I'm working with a vanilla electron app.我正在使用香草 electron 应用程序。 (npx create-electron-app......) (npx create-electron-app……)

Is it possible to do const electron = require("electron");是否可以做const electron = require("electron"); with nodeintegration:true ?nodeintegration:true

Im using a lib that does not support nodeintegration:true but my scripts need nodeintegration:true to run.我使用的库不支持nodeintegration:true但我的脚本需要nodeintegration:true才能运行。

Is there another way to access electron or node without nodeintegration:true ?是否有另一种方法可以访问 electron 或没有nodeintegration:true节点?

I don't think you can我不认为你可以
The Better option is to set更好的选择是设置

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

Where, options is the object you use while creating a BrowserWindow in electron.其中,options 是您在 electron 中创建BrowserWindow时使用的 object。

In preload.js ( I assume you want to use a lib called glob )在 preload.js 中(我假设你想使用一个名为 glob 的库

window.glob = require("glob");

Now anywhere in the HTML File (Frontend) you can refer to the lib as window.glob现在在 HTML 文件(前端)中的任何位置,您都可以将 lib 称为window.glob

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM