nuxt-electron
Advanced tools
+85
-48
@@ -28,5 +28,10 @@ "use strict"; | ||
| const kit = require("@nuxt/kit"); | ||
| const viteElectronPlugin = require("vite-electron-plugin"); | ||
| const vitePluginElectron = require("vite-plugin-electron"); | ||
| const __dirname$1 = path.dirname(url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : document.currentScript && document.currentScript.src || new URL("index.cjs", document.baseURI).href)); | ||
| const isProduction = process.env.NODE_ENV === "production"; | ||
| let options; | ||
| let nuxt; | ||
| let viteConfigResolve; | ||
| const viteConfigPromise = new Promise((resolve) => viteConfigResolve = resolve); | ||
| let viteServerResolve; | ||
| const viteServerPromise = new Promise((resolve) => viteServerResolve = resolve); | ||
| const index = kit.defineNuxtModule({ | ||
@@ -40,21 +45,28 @@ meta: { | ||
| }, | ||
| defaults: { | ||
| include: ["electron"], | ||
| outDir: "dist-electron" | ||
| }, | ||
| async setup(options, nuxt) { | ||
| adaptElectronConfig(options, nuxt); | ||
| if (options.renderer) { | ||
| nodeIntegration(options, nuxt); | ||
| } | ||
| nuxt.hook("build:manifest", (manifest) => { | ||
| for (const key in manifest) { | ||
| manifest[key].dynamicImports = []; | ||
| hooks: { | ||
| "nitro:config"(nitroConfig) { | ||
| if (options.renderer) { | ||
| nitroConfig.plugins ?? (nitroConfig.plugins = []); | ||
| nitroConfig.plugins.push(path.join(__dirname$1, "cjs-shim")); | ||
| } | ||
| }); | ||
| nuxt.hooks.addHooks({ | ||
| // For development | ||
| listen(server, listener) { | ||
| options.watch ?? (options.watch = {}); | ||
| options.plugins ?? (options.plugins = []); | ||
| }, | ||
| async "vite:extendConfig"(viteInlineConfig) { | ||
| viteInlineConfig.plugins ?? (viteInlineConfig.plugins = []); | ||
| viteInlineConfig.plugins.push({ | ||
| name: "get-vite-config", | ||
| configResolved(config) { | ||
| viteConfigResolve(config); | ||
| } | ||
| }); | ||
| if (options.renderer) { | ||
| viteInlineConfig.plugins.push((await import("vite-plugin-electron-renderer")).default(options.renderer)); | ||
| } | ||
| }, | ||
| "vite:serverCreated"(server) { | ||
| viteServerResolve(server); | ||
| }, | ||
| // For development | ||
| listen(server, listener) { | ||
| (async function _listen() { | ||
| var _a, _b, _c, _d; | ||
| const addressInfo = server.address(); | ||
@@ -65,36 +77,61 @@ Object.assign(process.env, { | ||
| }); | ||
| options.plugins.push({ | ||
| name: "nuxt-electron:startup", | ||
| ondone() { | ||
| viteElectronPlugin.startup(); | ||
| } | ||
| }); | ||
| viteElectronPlugin.watch(options); | ||
| }, | ||
| // For build | ||
| "build:done"() { | ||
| if (isProduction) | ||
| viteElectronPlugin.build(options); | ||
| for (const config of options.build) { | ||
| config.vite ?? (config.vite = {}); | ||
| (_a = config.vite).mode ?? (_a.mode = (await viteConfigPromise).mode); | ||
| (_b = config.vite).build ?? (_b.build = {}); | ||
| (_c = config.vite.build).watch ?? (_c.watch = {}); | ||
| (_d = config.vite).plugins ?? (_d.plugins = []); | ||
| config.vite.plugins.push({ | ||
| name: "nuxt-electron:startup", | ||
| closeBundle() { | ||
| if (config.onstart) { | ||
| config.onstart.call(this, { | ||
| startup: vitePluginElectron.startup, | ||
| reload() { | ||
| viteServerPromise.then((server2) => server2.ws.send({ type: "full-reload" })); | ||
| } | ||
| }); | ||
| } else { | ||
| vitePluginElectron.startup(); | ||
| } | ||
| } | ||
| }); | ||
| vitePluginElectron.build(config); | ||
| } | ||
| })(); | ||
| }, | ||
| // For build | ||
| async "build:done"() { | ||
| var _a; | ||
| if (!nuxt.options.dev) { | ||
| for (const config of options.build) { | ||
| config.vite ?? (config.vite = {}); | ||
| (_a = config.vite).mode ?? (_a.mode = (await viteConfigPromise).mode); | ||
| await vitePluginElectron.build(config); | ||
| } | ||
| } | ||
| }); | ||
| }, | ||
| "build:manifest"(manifest) { | ||
| for (const key in manifest) { | ||
| manifest[key].dynamicImports = []; | ||
| } | ||
| } | ||
| }, | ||
| async setup(_options, _nuxt) { | ||
| options = _options; | ||
| nuxt = _nuxt; | ||
| adaptElectronConfig(options, nuxt); | ||
| } | ||
| }); | ||
| function adaptElectronConfig(options, nuxt) { | ||
| function adaptElectronConfig(options2, nuxt2) { | ||
| var _a; | ||
| if (!options.disableDefaultOptions) { | ||
| nuxt.options.ssr = false; | ||
| nuxt.options.app.baseURL = "./"; | ||
| nuxt.options.app.buildAssetsDir = "/"; | ||
| nuxt.options.runtimeConfig.app.baseURL = "./"; | ||
| nuxt.options.runtimeConfig.app.buildAssetsDir = "/"; | ||
| if (!options2.disableDefaultOptions) { | ||
| nuxt2.options.ssr = false; | ||
| nuxt2.options.app.baseURL = "./"; | ||
| nuxt2.options.app.buildAssetsDir = "/"; | ||
| nuxt2.options.runtimeConfig.app.baseURL = "./"; | ||
| nuxt2.options.runtimeConfig.app.buildAssetsDir = "/"; | ||
| (_a = nuxt2.options.router.options).hashMode ?? (_a.hashMode = true); | ||
| } | ||
| (_a = nuxt.options.router.options).hashMode ?? (_a.hashMode = true); | ||
| } | ||
| async function nodeIntegration(options, nuxt) { | ||
| var _a, _b; | ||
| (_a = nuxt.options.vite).plugins ?? (_a.plugins = []); | ||
| nuxt.options.vite.plugins.push((await import("vite-plugin-electron-renderer")).default(options.renderer)); | ||
| (_b = nuxt.options.nitro).plugins ?? (_b.plugins = []); | ||
| nuxt.options.nitro.plugins.push(path.join(__dirname$1, "cjs-shim")); | ||
| } | ||
| exports.default = index; |
+23
-2
@@ -1,5 +0,24 @@ | ||
| import { type Configuration } from 'vite-electron-plugin'; | ||
| import { NuxtModule } from '@nuxt/schema'; | ||
| export interface ElectronOptions extends Partial<Configuration> { | ||
| export interface ElectronOptions { | ||
| /** | ||
| * `build` can specify multiple entry builds, which can be Main process, Preload scripts, Worker process, etc. | ||
| * | ||
| * @example | ||
| * | ||
| * ```js | ||
| * export default defineNuxtConfig({ | ||
| * modules: ['nuxt-electron'], | ||
| * electron: { | ||
| * build: [ | ||
| * { | ||
| * // Main-Process entry file of the Electron App. | ||
| * entry: 'electron/main.ts', | ||
| * }, | ||
| * ], | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| */ | ||
| build: import('vite-plugin-electron').Configuration[]; | ||
| /** | ||
| * @see https://github.com/electron-vite/vite-plugin-electron-renderer | ||
@@ -11,2 +30,4 @@ */ | ||
| * | ||
| * @defaultValue | ||
| * | ||
| * ```js | ||
@@ -13,0 +34,0 @@ * export default defineNuxtConfig({ |
+85
-48
| import path from "path"; | ||
| import { fileURLToPath } from "url"; | ||
| import { defineNuxtModule } from "@nuxt/kit"; | ||
| import { startup, watch, build } from "vite-electron-plugin"; | ||
| import { startup, build } from "vite-plugin-electron"; | ||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
| const isProduction = process.env.NODE_ENV === "production"; | ||
| let options; | ||
| let nuxt; | ||
| let viteConfigResolve; | ||
| const viteConfigPromise = new Promise((resolve) => viteConfigResolve = resolve); | ||
| let viteServerResolve; | ||
| const viteServerPromise = new Promise((resolve) => viteServerResolve = resolve); | ||
| const index = defineNuxtModule({ | ||
@@ -15,21 +20,28 @@ meta: { | ||
| }, | ||
| defaults: { | ||
| include: ["electron"], | ||
| outDir: "dist-electron" | ||
| }, | ||
| async setup(options, nuxt) { | ||
| adaptElectronConfig(options, nuxt); | ||
| if (options.renderer) { | ||
| nodeIntegration(options, nuxt); | ||
| } | ||
| nuxt.hook("build:manifest", (manifest) => { | ||
| for (const key in manifest) { | ||
| manifest[key].dynamicImports = []; | ||
| hooks: { | ||
| "nitro:config"(nitroConfig) { | ||
| if (options.renderer) { | ||
| nitroConfig.plugins ?? (nitroConfig.plugins = []); | ||
| nitroConfig.plugins.push(path.join(__dirname, "cjs-shim")); | ||
| } | ||
| }); | ||
| nuxt.hooks.addHooks({ | ||
| // For development | ||
| listen(server, listener) { | ||
| options.watch ?? (options.watch = {}); | ||
| options.plugins ?? (options.plugins = []); | ||
| }, | ||
| async "vite:extendConfig"(viteInlineConfig) { | ||
| viteInlineConfig.plugins ?? (viteInlineConfig.plugins = []); | ||
| viteInlineConfig.plugins.push({ | ||
| name: "get-vite-config", | ||
| configResolved(config) { | ||
| viteConfigResolve(config); | ||
| } | ||
| }); | ||
| if (options.renderer) { | ||
| viteInlineConfig.plugins.push((await import("vite-plugin-electron-renderer")).default(options.renderer)); | ||
| } | ||
| }, | ||
| "vite:serverCreated"(server) { | ||
| viteServerResolve(server); | ||
| }, | ||
| // For development | ||
| listen(server, listener) { | ||
| (async function _listen() { | ||
| var _a, _b, _c, _d; | ||
| const addressInfo = server.address(); | ||
@@ -40,38 +52,63 @@ Object.assign(process.env, { | ||
| }); | ||
| options.plugins.push({ | ||
| name: "nuxt-electron:startup", | ||
| ondone() { | ||
| startup(); | ||
| } | ||
| }); | ||
| watch(options); | ||
| }, | ||
| // For build | ||
| "build:done"() { | ||
| if (isProduction) | ||
| build(options); | ||
| for (const config of options.build) { | ||
| config.vite ?? (config.vite = {}); | ||
| (_a = config.vite).mode ?? (_a.mode = (await viteConfigPromise).mode); | ||
| (_b = config.vite).build ?? (_b.build = {}); | ||
| (_c = config.vite.build).watch ?? (_c.watch = {}); | ||
| (_d = config.vite).plugins ?? (_d.plugins = []); | ||
| config.vite.plugins.push({ | ||
| name: "nuxt-electron:startup", | ||
| closeBundle() { | ||
| if (config.onstart) { | ||
| config.onstart.call(this, { | ||
| startup, | ||
| reload() { | ||
| viteServerPromise.then((server2) => server2.ws.send({ type: "full-reload" })); | ||
| } | ||
| }); | ||
| } else { | ||
| startup(); | ||
| } | ||
| } | ||
| }); | ||
| build(config); | ||
| } | ||
| })(); | ||
| }, | ||
| // For build | ||
| async "build:done"() { | ||
| var _a; | ||
| if (!nuxt.options.dev) { | ||
| for (const config of options.build) { | ||
| config.vite ?? (config.vite = {}); | ||
| (_a = config.vite).mode ?? (_a.mode = (await viteConfigPromise).mode); | ||
| await build(config); | ||
| } | ||
| } | ||
| }); | ||
| }, | ||
| "build:manifest"(manifest) { | ||
| for (const key in manifest) { | ||
| manifest[key].dynamicImports = []; | ||
| } | ||
| } | ||
| }, | ||
| async setup(_options, _nuxt) { | ||
| options = _options; | ||
| nuxt = _nuxt; | ||
| adaptElectronConfig(options, nuxt); | ||
| } | ||
| }); | ||
| function adaptElectronConfig(options, nuxt) { | ||
| function adaptElectronConfig(options2, nuxt2) { | ||
| var _a; | ||
| if (!options.disableDefaultOptions) { | ||
| nuxt.options.ssr = false; | ||
| nuxt.options.app.baseURL = "./"; | ||
| nuxt.options.app.buildAssetsDir = "/"; | ||
| nuxt.options.runtimeConfig.app.baseURL = "./"; | ||
| nuxt.options.runtimeConfig.app.buildAssetsDir = "/"; | ||
| if (!options2.disableDefaultOptions) { | ||
| nuxt2.options.ssr = false; | ||
| nuxt2.options.app.baseURL = "./"; | ||
| nuxt2.options.app.buildAssetsDir = "/"; | ||
| nuxt2.options.runtimeConfig.app.baseURL = "./"; | ||
| nuxt2.options.runtimeConfig.app.buildAssetsDir = "/"; | ||
| (_a = nuxt2.options.router.options).hashMode ?? (_a.hashMode = true); | ||
| } | ||
| (_a = nuxt.options.router.options).hashMode ?? (_a.hashMode = true); | ||
| } | ||
| async function nodeIntegration(options, nuxt) { | ||
| var _a, _b; | ||
| (_a = nuxt.options.vite).plugins ?? (_a.plugins = []); | ||
| nuxt.options.vite.plugins.push((await import("vite-plugin-electron-renderer")).default(options.renderer)); | ||
| (_b = nuxt.options.nitro).plugins ?? (_b.plugins = []); | ||
| nuxt.options.nitro.plugins.push(path.join(__dirname, "cjs-shim")); | ||
| } | ||
| export { | ||
| index as default | ||
| }; |
+5
-8
| { | ||
| "name": "nuxt-electron", | ||
| "version": "0.4.5", | ||
| "version": "0.5.0", | ||
| "description": "Nuxt Integration with Electron", | ||
@@ -28,10 +28,6 @@ "main": "./dist/index.cjs", | ||
| "peerDependencies": { | ||
| "esbuild": "*", | ||
| "vite-electron-plugin": "*", | ||
| "vite-plugin-electron": "*", | ||
| "vite-plugin-electron-renderer": "*" | ||
| }, | ||
| "peerDependenciesMeta": { | ||
| "esbuild": { | ||
| "optional": true | ||
| }, | ||
| "vite-plugin-electron-renderer": { | ||
@@ -44,7 +40,8 @@ "optional": true | ||
| "esbuild": "^0.17.14", | ||
| "electron": "^24.3.1", | ||
| "nuxt": "^3.2.2", | ||
| "typescript": "^4.9.5", | ||
| "vite": "^4.1.4", | ||
| "vite-electron-plugin": "latest", | ||
| "vite-plugin-electron-renderer": "latest" | ||
| "vite-plugin-electron": "^0.11.2", | ||
| "vite-plugin-electron-renderer": "^0.14.4" | ||
| }, | ||
@@ -51,0 +48,0 @@ "files": [ |
+42
-28
@@ -15,5 +15,5 @@ <p align="center"> | ||
| - 🚀 High-performance <sub><sup>(Not Bundle, based on esbuild)</sup></sub> | ||
| - 📦 Out of the box | ||
| - 🔥 Hot restart | ||
| - 🔥 Hot restart <sub><sup>(Main process)</sup></sub> | ||
| - 🚀 Hot reload <sub><sup>(Preload script)</sup></sub> | ||
@@ -26,9 +26,9 @@ ## Quick Setup | ||
| # Using pnpm | ||
| pnpm add -D nuxt-electron vite-electron-plugin vite-plugin-electron-renderer electron electron-builder | ||
| pnpm add -D nuxt-electron vite-plugin-electron vite-plugin-electron-renderer electron electron-builder | ||
| # Using yarn | ||
| yarn add --dev nuxt-electron vite-electron-plugin vite-plugin-electron-renderer electron electron-builder | ||
| yarn add --dev nuxt-electron vite-plugin-electron vite-plugin-electron-renderer electron electron-builder | ||
| # Using npm | ||
| npm install --save-dev nuxt-electron vite-electron-plugin vite-plugin-electron-renderer electron electron-builder | ||
| npm install --save-dev nuxt-electron vite-plugin-electron vite-plugin-electron-renderer electron electron-builder | ||
| ``` | ||
@@ -40,5 +40,11 @@ | ||
| export default defineNuxtConfig({ | ||
| modules: [ | ||
| 'nuxt-electron', | ||
| ], | ||
| modules: ['nuxt-electron'], | ||
| electron: { | ||
| build: [ | ||
| { | ||
| // Main-Process entry file of the Electron App. | ||
| entry: 'electron/main.ts', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
@@ -69,25 +75,27 @@ ``` | ||
| Here is the default `electron` options | ||
| > This is based on the `vite-plugin-electron`, see the **[Documents](https://github.com/electron-vite/vite-plugin-electron)** for more detailed options | ||
| ```ts | ||
| export default defineNuxtConfig({ | ||
| modules: [ | ||
| 'nuxt-electron', | ||
| ], | ||
| electron: { | ||
| include: ['electron'], | ||
| outDir: 'dist-electron', | ||
| }, | ||
| }) | ||
| ``` | ||
| Full types definition | ||
| > This is based on the `vite-electron-plugin`, see the **[Documents](https://github.com/electron-vite/vite-electron-plugin#configuration)** for more detailed options | ||
| ```ts | ||
| import type { Configuration } from 'vite-electron-plugin' | ||
| export interface ElectronOptions extends Partial<Configuration> { | ||
| export interface ElectronOptions { | ||
| /** | ||
| * `build` can specify multiple entry builds, which can be Main process, Preload scripts, Worker process, etc. | ||
| * | ||
| * @example | ||
| * | ||
| * ```js | ||
| * export default defineNuxtConfig({ | ||
| * modules: ['nuxt-electron'], | ||
| * electron: { | ||
| * build: [ | ||
| * { | ||
| * // Main-Process entry file of the Electron App. | ||
| * entry: 'electron/main.ts', | ||
| * }, | ||
| * ], | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| */ | ||
| build: import('vite-plugin-electron').Configuration[], | ||
| /** | ||
| * @see https://github.com/electron-vite/vite-plugin-electron-renderer | ||
@@ -99,2 +107,4 @@ */ | ||
| * | ||
| * @defaultValue | ||
| * | ||
| * ```js | ||
@@ -158,1 +168,5 @@ * export default defineNuxtConfig({ | ||
| [license-href]: https://npmjs.com/package/nuxt-electron | ||
| ## TODO | ||
| - [ ] write test |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
17631
23.92%2
-33.33%326
41.13%167
9.15%2
-50%8
14.29%