From 03e5d93b27f5b8bf4229899611d1f41d4efde880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E4=BA=AE?= <2292735470@qq.com> Date: Wed, 3 May 2023 23:56:04 +0800 Subject: [PATCH] chore: 4.0.4 --- CHANGELOG.md | 4 +++ README.md | 10 ++++--- examples/demo/package.json | 2 +- examples/main+renderer/package.json | 2 +- lib/compile/index.js | 4 +++ lib/compile/vite/index.js | 4 +++ lib/compile/webpack/index.js | 4 +++ lib/index.js | 36 ++++++++++++----------- lib/setup.js | 4 +++ lib/utils/index.js | 4 +++ package.json | 2 +- src/index.ts | 44 ++++++++++++++++++----------- 12 files changed, 81 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 211d2a5..62ba9ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,3 +21,7 @@ ## 4.0.3(2023-02-05) 1、支持umi 4.0.49 + +## 4.0.4(2023-05-03) + +1、支持defineConfig类型提示 diff --git a/README.md b/README.md index 081ca1b..4b1a70d 100644 --- a/README.md +++ b/README.md @@ -128,8 +128,10 @@ $ pnpm i serialport @types/serialport ### 配置 .umirc.ts -```javascript +```typescript +import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain'; import { defineConfig } from 'umi'; +import { InlineConfig } from 'vite'; export default defineConfig({ electronBuilder: { @@ -153,19 +155,19 @@ export default defineConfig({ //使用时输出文件会和主进程在同一目录下 preload: path.join(__dirname, 'preload.js') 'index.ts': 'preload.js', }, - viteConfig(config: InlineConfig, type: ConfigType) { + viteConfig(config: InlineConfig, type: "main" | "preload") { //主进程Vite配置 //配置参考 https://vitejs.dev/config/ //ConfigType分为main和preload可分别配置 }, //通过 webpack-chain 的 API 修改 webpack 配置。 - mainWebpackChain(config: Config, type: ConfigType) { + mainWebpackChain(config: Config, type: "main" | "preload") { //ConfigType分为main和preload可分别配置 // if (type === 'main') {} // if (type === 'preload') {} }, //2.1.10新增 开启自定义主进程日志时 - logProcess(log: string, type: LogType) { + logProcess(log: string, type: "normal" | "error") { if (type === 'normal') { console.log(log); } else if (type === 'error') { diff --git a/examples/demo/package.json b/examples/demo/package.json index 3b20171..a21ee7f 100644 --- a/examples/demo/package.json +++ b/examples/demo/package.json @@ -25,7 +25,7 @@ "prettier-plugin-organize-imports": "^3.2.1", "prettier-plugin-packagejson": "^2.3.0", "typescript": "^4.9.4", - "umi-plugin-electron-builder": "^4.0.0" + "umi-plugin-electron-builder": "^4.0.4" }, "name": "electron_builder_app", "version": "0.0.1" diff --git a/examples/main+renderer/package.json b/examples/main+renderer/package.json index 7c91133..1d583cb 100644 --- a/examples/main+renderer/package.json +++ b/examples/main+renderer/package.json @@ -28,6 +28,6 @@ "prettier-plugin-organize-imports": "^3.2.1", "prettier-plugin-packagejson": "^2.3.0", "typescript": "^4.9.4", - "umi-plugin-electron-builder": "^4.0.0" + "umi-plugin-electron-builder": "^4.0.4" } } diff --git a/lib/compile/index.js b/lib/compile/index.js index cb8a7ad..d7199a1 100644 --- a/lib/compile/index.js +++ b/lib/compile/index.js @@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => { return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); diff --git a/lib/compile/vite/index.js b/lib/compile/vite/index.js index a007047..7210d1f 100644 --- a/lib/compile/vite/index.js +++ b/lib/compile/vite/index.js @@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => { return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); diff --git a/lib/compile/webpack/index.js b/lib/compile/webpack/index.js index 8edeec5..8a40836 100644 --- a/lib/compile/webpack/index.js +++ b/lib/compile/webpack/index.js @@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => { return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); diff --git a/lib/index.js b/lib/index.js index 938100c..0a221b4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => { return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); @@ -68,22 +72,22 @@ function src_default(api) { key: "electronBuilder", config: { default: defaultConfig, - schema(joi) { - return joi.object({ - buildType: joi.string(), - parallelBuild: joi.boolean(), - mainSrc: joi.string(), - preloadSrc: joi.string(), - outputDir: joi.string(), - externals: joi.array(), - builderOptions: joi.object(), - routerMode: joi.string(), - rendererTarget: joi.string(), - debugPort: joi.number(), - preloadEntry: joi.object(), - viteConfig: joi.func(), - mainWebpackChain: joi.func(), - logProcess: joi.func() + schema({ zod }) { + return zod.object({ + buildType: zod.enum(["vite", "webpack"]).optional(), + parallelBuild: zod.boolean().optional(), + mainSrc: zod.string().optional(), + preloadSrc: zod.string().optional(), + outputDir: zod.string().optional(), + externals: zod.string().array().optional(), + builderOptions: zod.record(zod.string(), zod.any()).optional(), + routerMode: zod.enum(["hash", "memory", "browser"]).optional(), + rendererTarget: zod.enum(["electron-renderer", "web"]).optional(), + debugPort: zod.number().optional(), + preloadEntry: zod.record(zod.string(), zod.string()).optional(), + viteConfig: zod.function().args(zod.any(), zod.enum(["main", "preload"])).returns(zod.void()).optional(), + mainWebpackChain: zod.function().args(zod.any(), zod.enum(["main", "preload"])).returns(zod.void()).optional(), + logProcess: zod.function().args(zod.string(), zod.enum(["normal", "error"])).returns(zod.void()).optional() }); } } diff --git a/lib/setup.js b/lib/setup.js index b36b872..2c6f633 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => { return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); diff --git a/lib/utils/index.js b/lib/utils/index.js index 7f2475b..dfa52fd 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => { return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); diff --git a/package.json b/package.json index e8e69ee..ac8ba3b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "umi-plugin-electron-builder", - "version": "4.0.3", + "version": "4.0.4", "description": "Umi plugin for electron-builder", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 3eca309..d84a263 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,22 +51,34 @@ export default function (api: IApi) { key: 'electronBuilder', config: { default: defaultConfig, - schema(joi) { - return joi.object({ - buildType: joi.string(), - parallelBuild: joi.boolean(), - mainSrc: joi.string(), - preloadSrc: joi.string(), - outputDir: joi.string(), - externals: joi.array(), - builderOptions: joi.object(), - routerMode: joi.string(), - rendererTarget: joi.string(), - debugPort: joi.number(), - preloadEntry: joi.object(), - viteConfig: joi.func(), - mainWebpackChain: joi.func(), - logProcess: joi.func(), + schema({ zod }) { + return zod.object({ + buildType: zod.enum(['vite', 'webpack']).optional(), + parallelBuild: zod.boolean().optional(), + mainSrc: zod.string().optional(), + preloadSrc: zod.string().optional(), + outputDir: zod.string().optional(), + externals: zod.string().array().optional(), + builderOptions: zod.record(zod.string(), zod.any()).optional(), + routerMode: zod.enum(['hash', 'memory', 'browser']).optional(), + rendererTarget: zod.enum(['electron-renderer', 'web']).optional(), + debugPort: zod.number().optional(), + preloadEntry: zod.record(zod.string(), zod.string()).optional(), + viteConfig: zod + .function() + .args(zod.any(), zod.enum(['main', 'preload'])) + .returns(zod.void()) + .optional(), + mainWebpackChain: zod + .function() + .args(zod.any(), zod.enum(['main', 'preload'])) + .returns(zod.void()) + .optional(), + logProcess: zod + .function() + .args(zod.string(), zod.enum(['normal', 'error'])) + .returns(zod.void()) + .optional(), }); }, },