![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
vite-plugin-electron
Advanced tools
Integrate Vite and Electron
English | 简体中文
Example 👉 vite-plugin-electron-quick-start
vite.config.ts
import electron from 'vite-plugin-electron'
export default {
plugins: [
electron({
main: {
entry: 'electron/main.ts',
},
}),
],
}
electron(config: Configuration)
import type { LibraryOptions, UserConfig } from 'vite'
import type { InputOption } from 'rollup'
export interface Configuration {
main: {
/**
* Shortcut of `build.lib.entry`
*/
entry: LibraryOptions['entry']
vite?: UserConfig
}
preload?: {
/**
* Shortcut of `build.rollupOptions.input`
*/
input: InputOption
vite?: UserConfig
}
}
The plugin is just the encapsulation of the built-in scripts of electron-vite-boilerplate/scripts
Let's use the vanilla-ts template created based on create vite
as an example
+ ├─┬ electron
+ │ └── main.ts
├─┬ src
│ ├── main.ts
│ ├── style.css
│ └── vite-env.d.ts
├── .gitignore
├── favicon.svg
├── index.html
├── package.json
├── tsconfig.json
+ └── vite.config.ts
🚨 By default, the files in electron
folder will be built into the dist/electron
🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧
Use Electron and Node.js API in Renderer-process
If you only need to build the Renderer-process, you can just use the
vite-plugin-electron/renderer
plugin
Example 👉 electron-vite-boilerplate/packages/renderer/vite.config.ts
vite.config.ts
import renderer from 'vite-plugin-electron/renderer'
export default {
plugins: [
renderer(),
],
}
renderer.js
import { readFile } from 'fs'
import { ipcRenderer } from 'electron'
readFile(/* something code... */)
ipcRenderer.on('event-name', () => {/* something code... */})
Using Electron API in Renderer-process
import { ipcRenderer } from 'electron'
↓
// Actually will redirect by `resolve.alias`
import { ipcRenderer } from 'vite-plugin-electron/renderer/modules/electron-renderer.js'
Using Node.js API in Renderer-process
import { readFile } from 'fs'
↓
// All Node.js API will redirect to the directory created based on `vite-plugin-optimizer` by `resolve.alias`
import { readFile } from '.vite-plugin-electron-renderer/fs'
Config presets
base = './'
build.assetsDir = ''
-> TODO: Automatic splicing build.assetsDir
build.emptyOutDir = false
build.cssCodeSplit = false
build.rollupOptions.output.format = 'cjs'
resolve.conditions = ['node']
electron
module into optimizeDeps.exclude
The plugin transform Electron and Node.js built-in modules to ESModule format in vite serve
phase.
Add Electron and Node.js built-in modules to Rollup output.external
option in the vite build
phase.
You may need to use some Node.js modules from npm in the Main-process/Renderer-process.
I suggest you look at electron-vite-boilerplate.
[2022-06-14] v0.4.9
build.cssCodeSplit=false
FAQs
Electron 🔗 Vite
The npm package vite-plugin-electron receives a total of 18,207 weekly downloads. As such, vite-plugin-electron popularity was classified as popular.
We found that vite-plugin-electron demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.