Socket
Socket
Sign inDemoInstall

vite-plugin-electron

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-electron - npm Package Compare versions

Comparing version 0.11.2 to 0.12.0

dist/utils.d.ts

31

dist/index.d.ts
import { type Plugin } from 'vite';
import { type Configuration } from './config';
export { type Configuration, defineConfig, resolveViteConfig, withExternalBuiltins, } from './config';
export declare function build(config: Configuration): Promise<import("rollup").RollupOutput | import("rollup").RollupOutput[] | import("rollup").RollupWatcher>;
export default function electron(config: Configuration | Configuration[]): Plugin[];
import { resolveViteConfig, withExternalBuiltins } from './utils';
export { resolveViteConfig, withExternalBuiltins, };
export interface ElectronOptions {
/**
* Shortcut of `build.lib.entry`
*/
entry?: import('vite').LibraryOptions['entry'];
vite?: import('vite').InlineConfig;
/**
* Triggered when Vite is built every time -- `vite serve` command only.
*
* If this `onstart` is passed, Electron App will not start automatically.
* However, you can start Electroo App via `startup` function.
*/
onstart?: (args: {
/**
* Electron App startup function.
* It will mount the Electron App child-process to `process.electronApp`.
* @param argv default value `['.', '--no-sandbox']`
*/
startup: (argv?: string[]) => Promise<void>;
/** Reload Electron-Renderer */
reload: () => void;
}) => void | Promise<void>;
}
export declare function build(options: ElectronOptions): Promise<import("rollup").RollupOutput | import("rollup").RollupOutput[] | import("rollup").RollupWatcher>;
export default function electron(options: ElectronOptions | ElectronOptions[]): Plugin[];
/**

@@ -7,0 +30,0 @@ * Electron App startup function.

55

dist/index.js

@@ -27,6 +27,3 @@ "use strict";

const node_module = require("node:module");
function defineConfig(config) {
return config;
}
function resolveViteConfig(option) {
function resolveViteConfig(options) {
const defaultConfig = {

@@ -38,4 +35,4 @@ // 🚧 Avoid recursive build caused by load config file

// @ts-ignore
lib: option.entry && {
entry: option.entry,
lib: options.entry && {
entry: options.entry,
// At present, Electron(20) can only support CommonJs

@@ -61,3 +58,3 @@ formats: ["cjs"],

};
return vite.mergeConfig(defaultConfig, (option == null ? void 0 : option.vite) || {});
return vite.mergeConfig(defaultConfig, (options == null ? void 0 : options.vite) || {});
}

@@ -115,7 +112,7 @@ function withExternalBuiltins(config) {

}
function build(config) {
return vite.build(withExternalBuiltins(resolveViteConfig(config)));
function build(options) {
return vite.build(withExternalBuiltins(resolveViteConfig(options)));
}
function electron(config) {
const configArray = Array.isArray(config) ? config : [config];
function electron(options) {
const optionsArray = Array.isArray(options) ? options : [options];
let mode;

@@ -129,17 +126,18 @@ return [

(_a = server.httpServer) == null ? void 0 : _a.once("listening", () => {
var _a2, _b, _c, _d;
var _a2, _b, _c, _d, _e;
Object.assign(process.env, {
VITE_DEV_SERVER_URL: resolveServerUrl(server)
});
for (const config2 of configArray) {
config2.vite ?? (config2.vite = {});
(_a2 = config2.vite).mode ?? (_a2.mode = server.config.mode);
(_b = config2.vite).build ?? (_b.build = {});
(_c = config2.vite.build).watch ?? (_c.watch = {});
(_d = config2.vite).plugins ?? (_d.plugins = []);
config2.vite.plugins.push({
for (const options2 of optionsArray) {
options2.vite ?? (options2.vite = {});
(_a2 = options2.vite).mode ?? (_a2.mode = server.config.mode);
(_b = options2.vite).build ?? (_b.build = {});
(_c = options2.vite.build).watch ?? (_c.watch = {});
(_d = options2.vite.build).minify ?? (_d.minify = false);
(_e = options2.vite).plugins ?? (_e.plugins = []);
options2.vite.plugins.push({
name: ":startup",
closeBundle() {
if (config2.onstart) {
config2.onstart.call(this, {
if (options2.onstart) {
options2.onstart.call(this, {
startup,

@@ -155,3 +153,3 @@ reload() {

});
build(config2);
build(options2);
}

@@ -164,4 +162,4 @@ });

apply: "build",
config(config2, env) {
config2.base ?? (config2.base = "./");
config(config, env) {
config.base ?? (config.base = "./");
mode = env.mode;

@@ -171,6 +169,6 @@ },

var _a;
for (const config2 of configArray) {
config2.vite ?? (config2.vite = {});
(_a = config2.vite).mode ?? (_a.mode = mode);
await build(config2);
for (const options2 of optionsArray) {
options2.vite ?? (options2.vite = {});
(_a = options2.vite).mode ?? (_a.mode = mode);
await build(options2);
}

@@ -202,5 +200,4 @@ }

exports.default = electron;
exports.defineConfig = defineConfig;
exports.resolveViteConfig = resolveViteConfig;
exports.startup = startup;
exports.withExternalBuiltins = withExternalBuiltins;
{
"name": "vite-plugin-electron",
"version": "0.11.2",
"version": "0.12.0",
"description": "Electron 🔗 Vite",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -36,3 +36,3 @@ <p align="center">

![vite-plugin-electron.gif](https://github.com/caoxiemeihao/blog/blob/main/vite/vite-plugin-electron.gif?raw=true)
<!-- ![vite-plugin-electron.gif](https://github.com/electron-vite/vite-plugin-electron/blob/main/vite-plugin-electron.gif?raw=true) -->

@@ -93,6 +93,6 @@ ## Quick Setup

`electron(config: Configuration | Configuration[])`
`electron(config: ElectronOptions | ElectronOptions[])`
```ts
export interface Configuration {
export interface ElectronOptions {
/**

@@ -155,4 +155,3 @@ * Shortcut of `build.lib.entry`

- `Configuration` - type
- `defineConfig` - function
- `ElectronOptions` - type
- `resolveViteConfig` - function, Resolve the default Vite's `InlineConfig` for build Electron-Main

@@ -200,20 +199,55 @@ - `withExternalBuiltins` - function

- 🚨 Currently, `"type": "module"` is not supported in Electron
- 🚨 In general, Vite may not correctly build Node.js packages, especially C/C++ native modules, but Vite can load them as external packages. So, put your Node.js package in `dependencies`. Unless you know how to properly build them with Vite.
```js
electron({
entry: 'electron/main.ts',
vite: {
build: {
rollupOptions: {
// Here are some C/C++ modules them can't be built properly.
external: [
'serialport',
'sqlite3',
],
## C/C++ Native
We have two ways to use C/C++ native modules
**First**
In general, Vite may not correctly build Node.js packages, especially C/C++ native modules, but Vite can load them as external packages
So, put your Node.js package in `dependencies`. Unless you know how to properly build them with Vite
```js
export default {
plugins: [
electron({
entry: 'electron/main.ts',
vite: {
build: {
rollupOptions: {
// Here are some C/C++ modules them can't be built properly
external: [
'serialport',
'sqlite3',
],
},
},
},
},
}),
```
}),
],
}
```
**Second**
Use 👉 [vite-plugin-native](https://github.com/vite-plugin/vite-plugin-native)
```js
import native from 'vite-plugin-native'
export default {
plugins: [
electron({
entry: 'electron/main.ts',
vite: {
plugins: [
native(/* options */),
],
},
}),
],
}
```
<!-- You can see 👉 [dependencies vs devDependencies](https://github.com/electron-vite/vite-plugin-electron-renderer#dependencies-vs-devdependencies) -->

Sorry, the diff of this file is not supported yet

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