项目输入: npm config edit
在registry 下面添加,并替换了 registry
- registry=https://registry.npm.taobao.org/
- disturl=https://npm.taobao.org/mirrors/node
- electron_mirror=https://cdn.npm.taobao.org/dist/electron/
- sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
安装electron失败 postinstall: `node install.js`
npm config set electron_mirror "https://npm.taobao.org/mirrors/electron/"
Electron预加载:
新建preload.js 在src下面
preload.js:
- var electron_re=require('electron')
- window.electron=electron_re
main.js:
- const {
- BrowserWindow,
- } = require('electron')
- new BrowserWindow({
- width: 1100,
- height: 720,
- minWidth: 1100,
- minHeight: 720,
- webPreferences: {
- nodeIntegration: true,
- preload: path.join(__dirname, '/preload.js'),
- nativeWindowOpen: true,
- contextIsolation: false,//需要false
- webSecurity: false
- },
- icon: `${__static}/icon/favicon.ico`
- })
- win.loadURL('app://./index.html')
vue.config.js:
- module.exports = {
- pluginOptions:{
- electronBuilder:{
- preload:'src/preload.js',
- target: "electron-renderer"
- }
- }
- }
打包可能遇到的问题
* 1. 打包时下载electron-v.xxxx.zip文件失败
* 解决办法:直接在淘宝的文件库下载对应版本和打包平台的文件,下载完成后放在 C:\Users\Administrator\AppData\Local\electron\Cache这个目录下
* 2. 打包时下载winCodeSign-v.xxx.7z文件失败
* 下载地址:https://github.com/electron-userland/electron-builder-binaries/releases/download/winCodeSign-2.5.0/winCodeSign-2.5.0.7z
* 下载完解压放到C:\Users\Administrator\AppData\Local\electron-builder\Cache\winCodeSign目录下
* 3. 打包时下载nsis-v.xxx.7z文件失败
* 下载地址:https://github.com/electron-userland/electron-builder-binaries/releases/download/nsis-3.0.3.2/nsis-3.0.3.2.7z
* 下载完解压放到C:\Users\Administrator\AppData\Local\electron-builder\Cache\nsis
* 4. 打包时下载nsis-resources-v.xxx.7z文件失败
* 下载地址:https://github.com/electron-userland/electron-builder-binaries/releases/download/nsis-resources-3.4.1/nsis-resources-3.4.1.7z
* 下载完解压放到C:\Users\Administrator\AppData\Local\electron-builder\Cache\nsis\nsis-resources-3.4.1