Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-electron-renderer

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-electron-renderer

Use Electron and NodeJs API in Renderer-process

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.4K
decreased by-27.79%
Maintainers
1
Weekly downloads
 
Created
Source

vite-plugin-electron-renderer

npm package
NPM version NPM Downloads

Use Electron and Node.js API in Renderer-process

English | 简体中文

Example 👉 electron-vite-boilerplate

Install

npm i vite-plugin-electron-renderer -D

Usage

vite.config.ts

import { defineConfig } from 'vite'
import electron from 'vite-plugin-electron-renderer'

export default defineConfig({
  plugins: [
    electron(),
  ],
})

renderer.js

import { readFile } from 'fs'
import { ipcRenderer } from 'electron'

readFile(/* something code... */)
ipcRenderer.on('event-name', () => {/* something code... */})

How to work

  • Using Electron API in Renderer-process
import { ipcRenderer } from 'electron'

Actually redirect to "node_modules/vite-plugin-electron-renderer/modules/electron-renderer.js" by resolve.alias

  • Using Node.js API in Renderer-process
import { readFile } from 'fs'

All Node.js API will be built into the node_modules/.vite-plugin-electron-renderer directory by vite-plugin-optimizer

🚧 Some additional instructions

  1. Fist, the plugin will configuration something.
  • If you do not configure the following options, the plugin will modify their default values

    • base = './'
    • build.assetsDir = '' -> TODO: Automatic splicing "build.assetsDir"
    • build.rollupOptions.output.format = 'cjs'
  1. The plugin transform Electron and Node.js built-in modules to ESModule format in "vite serve" phase.

  2. Add Electron and Node.js built-in modules to Rollup "output.external" option in the "vite build" phase.

Keywords

FAQs

Package last updated on 24 Mar 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc