UNPKG

5.96 kBTypeScriptView Raw
1import { Plugin } from 'vite';
2import { Configuration } from 'electron-builder';
3import { Options } from 'tsup';
4
5/**
6 * Electron main process options. See [tsup](https://tsup.egoist.dev/) and [API Doc](https://paka.dev/npm/tsup) for more information.
7 * @see https://paka.dev/npm/tsup
8 * @see https://unpkg.com/browse/tsup/dist/index.d.ts
9 */
10interface MainOptions extends Omit<Options, 'entry' | 'format' | 'outDir' | 'watch' | 'onSuccess'> {
11 /**
12 * The main process entry file.
13 */
14 entry?: string;
15 /**
16 * The bundle format. If not specified, it will use the "type" field from package.json.
17 */
18 format?: 'cjs' | 'esm';
19 /**
20 * The output directory for the main process files. Defaults to `"dist-electron/main"`.
21 * @default "dist-electron/main"
22 */
23 outDir?: string;
24 /**
25 * A function that will be executed after the build succeeds.
26 */
27 onSuccess?: () => Promise<void | undefined | (() => void | Promise<void>)>;
28}
29/**
30 * Electron preload process options. See [tsup](https://tsup.egoist.dev/) and [API Doc](https://paka.dev/npm/tsup) for more information.
31 * @see https://paka.dev/npm/tsup
32 * @see https://unpkg.com/browse/tsup/dist/index.d.ts
33 */
34interface PreloadOptions extends Omit<Options, 'entry' | 'format' | 'outDir' | 'watch' | 'onSuccess'> {
35 /**
36 * The preload process entry file
37 */
38 entry?: string | string[] | Record<string, string>;
39 /**
40 * The bundle format. If not specified, it will use the "type" field from package.json.
41 */
42 format?: 'cjs' | 'esm';
43 /**
44 * The output directory for the preload process files. Defaults is `"dist-electron/preload"`.
45 * @default "dist-electron/preload"
46 */
47 outDir?: string;
48 /**
49 * A function that will be executed after the build succeeds.
50 */
51 onSuccess?: () => Promise<void | undefined | (() => void | Promise<void>)>;
52}
53/**
54 * When `recommended` and `builder.enable` are both `true`, use [electron-builder](https://www.electron.build) to package Electron applications.
55 *
56 * * In the `build.outDir` directory configured in vite, generate a new package.json based on the configuration and package.json, excluding non-dependencies.
57 * * Execute `npm install` and then package.
58 */
59interface BuilderOptions {
60 /**
61 * Whether to enable the [electron-builder](https://www.electron.build), the default is false.
62 * @default true
63 * @deprecated
64 */
65 enable?: boolean;
66 /**
67 * The application id. Used as [CFBundleIdentifier](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-102070) for MacOS and as
68 * [Application User Model ID](https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx) for Windows (NSIS target only, Squirrel.Windows not supported). It is strongly recommended that an explicit ID is set.
69 * @default com.electron.${name}
70 */
71 appId?: string | null;
72 /**
73 * As [name](#Metadata-name), but allows you to specify a product name for your executable which contains spaces and other special characters not allowed in the [name property](https://docs.npmjs.com/files/package.json#name).
74 * If not specified inside of the `build` configuration, `productName` property defined at the top level of `package.json` is used. If not specified at the top level of `package.json`, [name property](https://docs.npmjs.com/files/package.json#name) is used.
75 */
76 productName?: string | null;
77 /**
78 * The [electron-builder](https://www.electron.build/configuration/configuration) configuration.
79 */
80 builderConfig?: Configuration;
81}
82/**
83 * vite plugin options
84 */
85interface PluginOptions {
86 /**
87 * Recommended switch. Default is true.
88 * if true, will have the following default behavior:
89 * * will change the main/preload/renderer outDir to be parallel outDir;
90 * eg. if vite build.outDir is 'dist', will change main/preload/render to 'dist/main' and 'dist/preload' and 'dist/renderer'
91 * @default true
92 */
93 recommended?: boolean;
94 /**
95 * Don't bundle these modules, but dependencies and peerDependencies in your package.json are always excluded. [See more](https://tsup.egoist.dev/#excluding-packages)
96 * @see https://tsup.egoist.dev/#excluding-packages
97 */
98 external?: (string | RegExp)[];
99 /**
100 * electron main process options
101 */
102 main?: MainOptions;
103 /**
104 * electron preload process options
105 */
106 preload?: PreloadOptions;
107 /**
108 * When `recommended` and `builder.enable` are both `true`, use [electron-builder](https://www.electron.build) to package Electron applications.
109 *
110 * * In the `build.outDir` directory configured in vite, generate a new package.json based on the configuration and package.json, excluding non-dependencies.
111 * * Execute `npm install` and then package.
112 */
113 builder?: boolean | BuilderOptions;
114 /**
115 * electron debug mode, don't startup electron. You can also use `process.env.VITE_ELECTRON_DEBUG`. Default is false.
116 * @default false
117 */
118 debug?: boolean;
119 /**
120 * Electron will listen for V8 inspector protocol messages on the specified port, an external debugger will need to connect on this port.
121 * You can also use `process.env.VITE_ELECTRON_INSPECT`. See [debugging-main-process](https://www.electronjs.org/docs/latest/tutorial/debugging-main-process) for more information.
122 * The default port is false.
123 * @see https://www.electronjs.org/docs/latest/tutorial/debugging-main-process
124 * @default false
125 */
126 inspect?: number | boolean;
127}
128
129/**
130 * A simple vite plugin for electron
131 * @param options
132 */
133declare function useElectronPlugin(options?: PluginOptions): Plugin;
134
135export { BuilderOptions, MainOptions, PluginOptions, PreloadOptions, useElectronPlugin as default, useElectronPlugin };
136
\No newline at end of file