Skip to content

Commit

Permalink
feat: umi electron support routerMode config for hash or memory
Browse files Browse the repository at this point in the history
  • Loading branch information
liangskyli committed Aug 1, 2023
1 parent 6a3d7a8 commit e4f1378
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion examples/max/.umirc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { IElectronConfig } from '@liangskyli/umijs-plugin-electron';
import { defineConfig } from '@umijs/max';

const electron: IElectronConfig = {};
const electron: IElectronConfig = {
routerMode: 'memory',
};
export default defineConfig({
npmClient: 'pnpm',
plugins: ['@liangskyli/umijs-plugin-electron'],
Expand Down
10 changes: 9 additions & 1 deletion packages/umijs-plugin-electron/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const defaultConfig: ElectronConfig = {
builderOptions: {},
externals: [],
outputDir: 'dist_electron',
routerMode: 'hash',
debugPort: 5858,
preloadEntry: {
'index.ts': 'preload.js',
Expand Down Expand Up @@ -53,6 +54,7 @@ export default function (api: IApi) {
outputDir: zod.string().optional(),
externals: zod.string().array().optional(),
builderOptions: zod.record(zod.string(), zod.any()).optional(),
routerMode: zod.enum(['hash', 'memory']).optional(),
debugPort: zod.number().optional(),
preloadEntry: zod.record(zod.string(), zod.string()).optional(),
viteConfig: zod
Expand Down Expand Up @@ -116,11 +118,17 @@ export default function (api: IApi) {
api.modifyConfig((oldConfig) => {
const config = lodash.merge({ electron: defaultConfig }, oldConfig);

const { outputDir, externals } = config.electron as ElectronConfig;
const { outputDir, externals, routerMode } =
config.electron as ElectronConfig;
config.outputPath = path.join(outputDir, 'bundled');
config.alias = config.alias || {};
config.alias['@/common'] = path.join(process.cwd(), 'src/common');

config.history = config.history || {
type: routerMode,
};
config.history.type = routerMode;

const configExternals: any = {
electron: 'require(\'electron\')',
};
Expand Down
4 changes: 4 additions & 0 deletions packages/umijs-plugin-electron/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export type ConfigType = 'main' | 'preload';

export type LogType = 'normal' | 'error';

export type RouterMode = 'hash' | 'memory';

export interface ElectronConfig {
/** 主进程src目录 */
mainSrc: string;
Expand All @@ -14,6 +16,8 @@ export interface ElectronConfig {
externals: string[];
/** 打包目录 */
outputDir: string;
/** 路由模式 */
routerMode: RouterMode;
/** 打包参数
* see: https://www.electron.build/configuration/configuration
* */
Expand Down

0 comments on commit e4f1378

Please sign in to comment.