@tomjs/vite-plugin-electron 2.4.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -215,7 +215,7 @@ export default defineConfig({
215
215
  | debug | `boolean` | `false` | Electron debug mode, don't startup electron. You can also use `process.env.VITE_ELECTRON_DEBUG`. Default is false. |
216
216
  | builder | `boolean` \| [BuilderOptions](#BuilderOptions) | `false` | If it is a `boolean` type, whether to enable [electron-builder](https://www.electron.build). If it is an object, it is the [configuration](https://www.electron.build/configuration/configuration) of [electron-builder](https://www.electron.build). You can also turn it on using `process.env.VITE_ELECTRON_DEBUG`. |
217
217
  | inspect | `boolean` | `false` | Electron will listen for V8 inspector protocol messages on the specified port, an external debugger will need to connect on this port. 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. |
218
- | devtools | `boolean` \| `number` | `true` | If `true`, depending on whether the `react` plugin exists, inject `<script src="http://localhost:8097"></script>` code for [react-devtools](https://github.com/facebook/react/tree/main/packages/react-devtools); depending on whether the `vue` plugin exists, inject `<script src="http://localhost:8097"></script>` for [vue-devtools](https://devtools.vuejs.org/guide/standalone) debugging; if `number`, it is a custom port. |
218
+ | devtools | `boolean` \| `number` | `false` | If `true`, depending on whether the `react` plugin exists, inject `<script src="http://localhost:8097"></script>` code for [react-devtools](https://github.com/facebook/react/tree/main/packages/react-devtools); depending on whether the `vue` plugin exists, inject `<script src="http://localhost:8097"></script>` for [vue-devtools](https://devtools.vuejs.org/guide/standalone) debugging; if `number`, it is a custom port. |
219
219
 
220
220
  **Notice**
221
221
 
@@ -256,6 +256,8 @@ When `recommended` and `builder.enable` are both `true`, use [electron-builder](
256
256
  - In the `build.outDir` directory configured in vite, generate a new package.json based on the configuration and package.json, excluding non-dependencies.
257
257
  - Execute `npm install` and then package.
258
258
 
259
+ Reference [vite-plugin-electron-renderer](https://github.com/electron-vite/vite-plugin-electron-renderer) and [Two package.json Structure](https://www.electron.build/tutorials/two-package-structure)
260
+
259
261
  _Not suitable for everyone._
260
262
 
261
263
  To use this function, you need to install additional `electron-builder`
package/README.zh_CN.md CHANGED
@@ -252,8 +252,9 @@ export default defineConfig({
252
252
 
253
253
  当 `recommended` 和 `builder.enable` 都为 `true` 时,使用 [electron-builder](https://www.electron.build) 打包 Electron 应用程序。
254
254
 
255
- - 在vite中配置的`build.outDir`目录中,根据配置和package.json生成新的package.json,排除非依赖项。
256
- - 执行`npm install`然后打包。
255
+ - 在vite中配置的`build.outDir`目录中,根据配置和package.json生成新的package.json
256
+
257
+ 参考 [vite-plugin-electron-renderer](https://github.com/electron-vite/vite-plugin-electron-renderer) 和 [Two package.json Structure](https://www.electron.build/tutorials/two-package-structure)
257
258
 
258
259
  _不适合所有人使用。_
259
260
 
package/dist/index.d.mts CHANGED
@@ -91,11 +91,6 @@ interface PluginOptions {
91
91
  * @default true
92
92
  */
93
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
94
  /**
100
95
  * electron main process options
101
96
  */
package/dist/index.mjs CHANGED
@@ -4,7 +4,6 @@ import path from "node:path";
4
4
  import cloneDeep from "lodash.clonedeep";
5
5
  import merge from "lodash.merge";
6
6
  import os from "node:os";
7
- import { cwd } from "node:process";
8
7
  import { execa, execaSync } from "execa";
9
8
  import { createLogger } from "vite";
10
9
  import cp, { spawn } from "node:child_process";
@@ -175,12 +174,12 @@ function createPkg(options, resolvedConfig) {
175
174
  } else main = `main/index.${options?.main?.format === "esm" ? "" : "m"}js`;
176
175
  const newPkg = {
177
176
  name: pkg.name,
177
+ productName: pkg.productName,
178
178
  version: pkg.version,
179
179
  description: pkg.description,
180
180
  type: pkg.type || "commonjs",
181
- author: getAuthor(pkg.author),
182
- main,
183
- dependencies: getDeps()
181
+ author: pkg.author || getAuthor(pkg.author),
182
+ main
184
183
  };
185
184
  writeJson(path.join(outDir, "package.json"), newPkg);
186
185
  function getAuthor(author) {
@@ -194,33 +193,12 @@ function createPkg(options, resolvedConfig) {
194
193
  }
195
194
  return uname;
196
195
  }
197
- function checkDepName(rules, name) {
198
- return !!rules.find((s) => {
199
- if (typeof s === "string") return s.includes(name);
200
- else return s.test(name);
201
- });
202
- }
203
- function getDeps() {
204
- const deps = pkg.dependencies || {};
205
- const newDeps = {};
206
- Object.keys(deps).forEach((name) => {
207
- if (checkDepName(externals, name)) newDeps[name] = deps[name];
208
- });
209
- return newDeps;
210
- }
211
196
  return newPkg;
212
197
  }
213
198
  async function runElectronBuilder(options, resolvedConfig) {
214
199
  if (typeof options.builder == "boolean" && options.builder === false) return;
215
- logger.info("building electron app...");
216
- const DIST_PATH = path.join(cwd(), path.dirname(resolvedConfig.build.outDir));
217
200
  createPkg(options, resolvedConfig);
218
- logger.info(`create package.json and exec "npm install"`);
219
- execaSync(`npm install --emit=dev`, {
220
- cwd: DIST_PATH,
221
- shell: true
222
- });
223
- logger.info(`run electron-builder to package app`);
201
+ logger.info(`created package.json`);
224
202
  const config = getBuilderConfig(options, resolvedConfig);
225
203
  const { build: build$1 } = await import("electron-builder");
226
204
  await build$1({ config });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tomjs/vite-plugin-electron",
3
3
  "type": "module",
4
- "version": "2.4.1",
4
+ "version": "2.5.0",
5
5
  "description": "A simple vite plugin for electron, supports esm/cjs, support esm in electron v28+",
6
6
  "author": {
7
7
  "name": "Tom Gao",