{"_id":"@51kik/vite-plugin-electron","name":"@51kik/vite-plugin-electron","dist-tags":{"latest":"0.15.3"},"versions":{"0.15.3":{"name":"@51kik/vite-plugin-electron","version":"0.15.3","description":"Electron 🔗 Vite","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"},"./plugin":{"types":"./dist/plugin.d.ts","import":"./dist/plugin.mjs","require":"./dist/plugin.js"},"./simple":{"types":"./dist/simple.d.ts","import":"./dist/simple.mjs","require":"./dist/simple.js"},"./*":"./*"},"repository":{"type":"git","url":"git+https://github.com/siykt/vite-plugin-electron.git"},"author":{"name":"Siykt","email":"cnsiykt@163.com"},"license":"MIT","packageManager":"pnpm@8.0.0","peerDependencies":{"tree-kill":"*","vite-plugin-electron-renderer":"*"},"peerDependenciesMeta":{"vite-plugin-electron-renderer":{"optional":true},"tree-kill":{"optional":true}},"devDependencies":{"rollup":"^3.29.4","tree-kill":"^1.2.2","typescript":"^5.2.2","vite":"^4.5.0","vite-plugin-electron-renderer":"^0.14.5","vitest":"^0.34.6"},"keywords":["vite","plugin","electron","renderer"],"scripts":{"dev":"vite build --watch","build":"vite build","types":"tsc","test":"vitest run"},"bugs":{"url":"https://github.com/siykt/vite-plugin-electron/issues"},"homepage":"https://github.com/siykt/vite-plugin-electron#readme","_id":"@51kik/vite-plugin-electron@0.15.3","_integrity":"sha512-0UaehP+P5GVt1RLgo/s91YcpqNlfeaj1fGSTU3KHDHMNcu59DD5CxdUxNOnyJKBgp+Tx1+UCrHLe/h+DMcC5xQ==","_resolved":"/private/var/folders/8h/6kht9rs15kd0_jl_jwkk7kfr0000gn/T/7314624ae79cfe5fea35dd3165ddc499/51kik-vite-plugin-electron-0.15.3.tgz","_from":"file:51kik-vite-plugin-electron-0.15.3.tgz","_nodeVersion":"16.20.2","_npmVersion":"8.19.4","dist":{"integrity":"sha512-0UaehP+P5GVt1RLgo/s91YcpqNlfeaj1fGSTU3KHDHMNcu59DD5CxdUxNOnyJKBgp+Tx1+UCrHLe/h+DMcC5xQ==","shasum":"ff1b917d97b33855893524d74e6c721f5c654796","tarball":"https://registry.npmjs.org/@51kik/vite-plugin-electron/-/vite-plugin-electron-0.15.3.tgz","fileCount":18,"unpackedSize":49590,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFyWHUjREQ7vHpUl6yman70gYtSADqIryRt48OFUQWEqAiBmmWnH7EnGAmBGjf56o+mEZxLEhSNsIxRZpAICvTIZwA=="}]},"_npmUser":{"name":"siykt","email":"cnsiykt@163.com"},"directories":{},"maintainers":[{"name":"siykt","email":"cnsiykt@163.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/vite-plugin-electron_0.15.3_1699346664850_0.9572280920355754"},"_hasShrinkwrap":false}},"time":{"created":"2023-11-07T08:44:24.750Z","0.15.3":"2023-11-07T08:44:25.114Z","modified":"2023-11-07T08:44:25.469Z"},"maintainers":[{"name":"siykt","email":"cnsiykt@163.com"}],"description":"Electron 🔗 Vite","homepage":"https://github.com/siykt/vite-plugin-electron#readme","keywords":["vite","plugin","electron","renderer"],"repository":{"type":"git","url":"git+https://github.com/siykt/vite-plugin-electron.git"},"author":{"name":"Siykt","email":"cnsiykt@163.com"},"bugs":{"url":"https://github.com/siykt/vite-plugin-electron/issues"},"license":"MIT","readme":"<p align=\"center\">\n  <img width=\"170\" src=\"https://github.com/electron-vite/vite-plugin-electron/blob/main/logo.svg?raw=true\">\n</p>\n<div align=\"center\">\n  <h1>vite-plugin-electron</h1>\n</div>\n<p align=\"center\">Electron 🔗 Vite</p>\n<p align=\"center\">\n  <a href=\"https://npmjs.com/package/vite-plugin-electron\">\n    <img src=\"https://img.shields.io/npm/v/vite-plugin-electron.svg\">\n  </a>\n  <a href=\"https://npmjs.com/package/vite-plugin-electron\">\n    <img src=\"https://img.shields.io/npm/dm/vite-plugin-electron.svg\">\n  </a>\n  <a href=\"https://discord.gg/YfjFuEgVUR\">\n    <img src=\"https://img.shields.io/badge/chat-discord-blue?logo=discord\">\n  </a>\n</p>\n<p align=\"center\">\n  <strong>\n    <span>English</span>\n    |\n    <a href=\"https://github.com/electron-vite/vite-plugin-electron/blob/main/README.zh-CN.md\">简体中文</a>\n  </strong>\n</p>\n\n<br/>\n\nIn short, `vite-plugin-electron` makes developing Electron apps as easy as normal Vite projects.\n\n## Features\n\n- [🔥 Hot Restart <sub><sup>(Main process)</sup></sub>](https://electron-vite.github.io/guide/features.html#hot-restart)\n- [🔄 Hot Reload <sub><sup>(Preload scripts)</sup></sub>](https://electron-vite.github.io/guide/features.html#hot-reload)\n- [⚡️ HMR <sub><sup>(Renderer process)</sup></sub>](https://electron-vite.github.io/guide/features.html#hmr)\n- [🚀 Not Bundle, It's fast <sub><sup>(Like Vite's Not Bundle)</sup></sub>](https://github.com/electron-vite/vite-plugin-electron#not-bundle)\n- 🌱 Fully compatible with Vite and Vite's ecosystem <sub><sup>(Based on Vite)</sup></sub>\n- 🐣 Few APIs, easy to use\n\n<!-- ![vite-plugin-electron.gif](https://github.com/electron-vite/vite-plugin-electron/blob/main/vite-plugin-electron.gif?raw=true) -->\n\n## Quick Setup\n\n1. Add the following dependency to your project\n\n```sh\nnpm i -D vite-plugin-electron\n```\n\n2. Add `vite-plugin-electron` to the `plugins` section of `vite.config.ts`\n\n```js\nimport electron from 'vite-plugin-electron'\n\nexport default {\n  plugins: [\n    electron({\n      entry: 'electron/main.ts',\n    }),\n  ],\n}\n```\n\n3. Create the `electron/main.ts` file and type the following code\n\n```js\nimport { app, BrowserWindow } from 'electron'\n\napp.whenReady().then(() => {\n  const win = new BrowserWindow({\n    title: 'Main window',\n  })\n\n  // You can use `process.env.VITE_DEV_SERVER_URL` when the vite command is called `serve`\n  if (process.env.VITE_DEV_SERVER_URL) {\n    win.loadURL(process.env.VITE_DEV_SERVER_URL)\n  } else {\n    // Load your file\n    win.loadFile('dist/index.html');\n  }\n})\n```\n\n4. Add the `main` entry to `package.json`\n\n```diff\n{\n+ \"main\": \"dist-electron/main.js\"\n}\n```\n\nThat's it! You can now use Electron in your Vite app ✨\n\n## Simple API\n\nMany times, for a developer who is new to Vite and Electron, the oversimplified and open API design is confusing to them. Maybe Simple API makes them easier to understand. :)\n\n```js\n// Just like v0.9.x\nimport electron from 'vite-plugin-electron/simple'\n\nexport default {\n  plugins: [\n    electron({\n      main: {\n        // Shortcut of `build.lib.entry`\n        entry: 'electron/main.ts',\n      },\n      preload: {\n        // Shortcut of `build.rollupOptions.input`\n        input: 'electron/preload.ts',\n      },\n      // Optional: Use Node.js API in the Renderer process\n      renderer: {},\n    }),\n  ],\n}\n```\n\n## API <sub><sup>(Define)</sup></sub>\n\n`electron(options: ElectronOptions | ElectronOptions[])`\n\n```ts\nexport interface ElectronOptions {\n  /**\n   * Shortcut of `build.lib.entry`\n   */\n  entry?: import('vite').LibraryOptions['entry']\n  vite?: import('vite').InlineConfig\n  /**\n   * Triggered when Vite is built every time -- `vite serve` command only.\n   * \n   * If this `onstart` is passed, Electron App will not start automatically.  \n   * However, you can start Electroo App via `startup` function.  \n   */\n  onstart?: (args: {\n    /**\n     * Electron App startup function.  \n     * It will mount the Electron App child-process to `process.electronApp`.  \n     * @param argv default value `['.', '--no-sandbox']`\n     */\n    startup: (argv?: string[]) => Promise<void>\n    /** Reload Electron-Renderer */\n    reload: () => void\n  }) => void | Promise<void>\n}\n```\n\n## Recommend Structure\n\nLet's use the official [template-vanilla-ts](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-vanilla-ts) created based on `create vite` as an example\n\n```diff\n+ ├─┬ electron\n+ │ └── main.ts\n  ├─┬ src\n  │ ├── main.ts\n  │ ├── style.css\n  │ └── vite-env.d.ts\n  ├── .gitignore\n  ├── favicon.svg\n  ├── index.html\n  ├── package.json\n  ├── tsconfig.json\n+ └── vite.config.ts\n```\n\n## Examples\n\nThere are many cases here 👉 [electron-vite-samples](https://github.com/caoxiemeihao/electron-vite-samples)\n\n## JavaScript API\n\n`vite-plugin-electron`'s JavaScript APIs are fully typed, and it's recommended to use TypeScript or enable JS type checking in VS Code to leverage the intellisense and validation.\n\n- `ElectronOptions` - type\n- `resolveViteConfig` - function, Resolve the default Vite's `InlineConfig` for build Electron-Main\n- `withExternalBuiltins` - function\n- `build` - function\n- `startup` - function\n\n**Example**\n\n```js\nimport { build, startup } from 'vite-plugin-electron'\n\nconst isDev = process.env.NODE_ENV === 'development'\nconst isProd = process.env.NODE_ENV === 'production'\n\nbuild({\n  entry: 'electron/main.ts',\n  vite: {\n    mode: process.env.NODE_ENV,\n    build: {\n      minify: isProd,\n      watch: isDev ? {} : null,\n    },\n    plugins: [{\n      name: 'plugin-start-electron',\n      closeBundle() {\n        if (isDev) {\n          // Startup Electron App\n          startup()\n        }\n      },\n    }],\n  },\n})\n```\n\n## How to work\n\nIt just executes the `electron .` command in the Vite build completion hook and then starts or restarts the Electron App.\n\n## Be aware\n\n- 🚨 By default, the files in `electron` folder will be built into the `dist-electron`\n- 🚨 Currently, `\"type\": \"module\"` is not supported in Electron\n\n## C/C++ Native\n\nWe have two ways to use C/C++ native modules\n\n**First way**\n\nIn general, Vite may not correctly build Node.js packages, especially C/C++ native modules, but Vite can load them as external packages\n\nSo, put your Node.js package in `dependencies`. Unless you know how to properly build them with Vite\n\n```js\nexport default {\n  plugins: [\n    electron({\n      entry: 'electron/main.ts',\n      vite: {\n        build: {\n          rollupOptions: {\n            // Here are some C/C++ modules them can't be built properly\n            external: [\n              'serialport',\n              'sqlite3',\n            ],\n          },\n        },\n      },\n    }),\n  ],\n}\n```\n\n**Second way**\n\nUse 👉 [vite-plugin-native](https://github.com/vite-plugin/vite-plugin-native)\n\n```js\nimport native from 'vite-plugin-native'\n\nexport default {\n  plugins: [\n    electron({\n      entry: 'electron/main.ts',\n      vite: {\n        plugins: [\n          native(/* options */),\n        ],\n      },\n    }),\n  ],\n}\n```\n\n<!-- You can see 👉 [dependencies vs devDependencies](https://github.com/electron-vite/vite-plugin-electron-renderer#dependencies-vs-devdependencies) -->\n\n---\n\n## Not Bundle\n\n> Added in: v0.13.0\n\nDuring the development phase, we can exclude the `cjs` format of npm-pkg from bundle. Like Vite's [👉 Not Bundle](https://vitejs.dev/guide/why.html#why-not-bundle-with-esbuild). **It's fast**!\n\n```js\nimport electron from 'vite-plugin-electron'\nimport { notBundle } from 'vite-plugin-electron/plugin'\n\nexport default defineConfig(({ command }) => ({\n  plugins: [\n    electron({\n      entry: 'electron/main.ts',\n      vite: {\n        plugins: [\n          command === 'serve' && notBundle(/* NotBundleOptions */),\n        ],\n      },\n    }),\n  ],\n}))\n```\n\n**API**\n\n`notBundle(/* NotBundleOptions */)`\n\n```ts\nexport interface NotBundleOptions {\n  filter?: (id: string) => void | false\n}\n```\n\n**How to work**\n\nLet's use the `electron-log` as an examples.\n\n```js\n┏—————————————————————————————————————┓\n│ import log from 'electron-log'      │\n┗—————————————————————————————————————┛\n                   ↓\nModules in `node_modules` are not bundled during development, it's fast!\n                   ↓\n┏—————————————————————————————————————┓\n│ const log = require('electron-log') │\n┗—————————————————————————————————————┛\n```\n\n## FAQ\n\n- `electron` does not exit correctly | 使用ctrl + c 停止代码，electron后台不关闭 | [#122](https://github.com/electron-vite/vite-plugin-electron/pull/122), [#168](https://github.com/electron-vite/vite-plugin-electron/issues/168)\n\n  * Add `tree-kill` into you dependencies, `npm i -D tree-kill`.\n\n","readmeFilename":"README.md"}