Socket
Socket
Sign inDemoInstall

vitejs-plugin-electron

Package Overview
Dependencies
1
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vitejs-plugin-electron

An vite plugin for electron integrate


Version published
Weekly downloads
9
Maintainers
1
Created
Weekly downloads
 

Readme

Source

An vite plugin for electron integration.

usage

  • vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import electron from 'vitejs-plugin-electron'

export default defineConfig((env) => ({
  plugins: [
    vue(),
    electron(),
  ],
  // other config...
}))

renderer/foo.ts

// You code
import { ipcRenderer } from 'electron'
import Store from 'electron-store'

// Will be generate in development mode
const { ipcRenderer } = require("electron")
const Store = require("electron-store")

Principe | 原理

The plugin is do only two things | 插件只做了两件事
  1. In the development phase, the modules related to Electron are compiled into CommonJs syntax
    在开发期将 Electron 相关的模块编译成了 CommonJs 格式
// You code
import { ipcRenderer } from 'electron'
import Store from 'electron-store'

// Will be generate in development mode
const { ipcRenderer } = require("electron")
const Store = require("electron-store")
  1. Add some config options into vite.config.ts
    增加了 vite.config.ts 默认配置
{
  optimizeDeps: {
    exclude: [
      'electron'
    ]
  },
  build: {
    rollupOptions: {
      external: [
        'electron'
      ],
      output: {
        format: 'cjs'
      }
    }
  }
}

Keywords

FAQs

Last updated on 30 May 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc