# electron **Repository Path**: hpstream/electron ## Basic Information - **Project Name**: electron - **Description**: 学习 electron 使用的项目 - **Primary Language**: JavaScript - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-04-04 - **Last Updated**: 2021-04-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # electron ## electron 项目初始化 ``` mkdir electron-demo && cd electron-demo npm init -y npm i --save-dev electron ``` > 安装不上可以使用 cnpm i --save-dev electron (淘宝镜像) ## api 的使用 1. BrowserWindow -> webPreferences ```json webPreferences: { sandbox: true, // 开启沙河环境 preload: path.join(__dirname, './preload.js'),// 预先执行脚本 contextIsolation: false, // 在 Electron 12+ 设置为false,在渲染进程才能使用require; webSecurity: false, // 关闭同源策略 nodeIntegration: true, // 设置开启nodejs环境 enableRemoteModule: true // enableRemoteModule保证renderer.js可以可以正常require('electron').remote,此选项默认关闭且网上很多资料没有提到 } ``` ## 构建应用 > npm run pack ## 注意事项: 1. 在 Electron 12+ 之后,contextIsolation 设置为false,在渲染进程中才能使用require语法