Skip to content

Commit

Permalink
feat: add dev layout
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohuoni committed Dec 1, 2023
1 parent cf1cc3c commit ff69235
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
18 changes: 3 additions & 15 deletions .umirc.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
import { defineConfig } from '@umijs/max';

export default defineConfig({
locale: {
// default zh-CN
default: 'zh-CN',
// default true, when it is true, will use `navigator.language` overwrite default
antd: true,
baseNavigator: true,
},
antd: {},
request: {},
targets: {
ie: 11,
},
// chainWebpack(memo) {
// memo.module.rule('ts-in-node_modules').include.clear();
// return memo;
// },
dva: {},
mfsu: false,
// webpack5: {},
// layout: {
// disableContentMargin: false,
// },
layout: {
title: 'pro-blocks',
},
});
29 changes: 19 additions & 10 deletions plugin.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { IApi } from '@umijs/max';
import { join } from 'path';
import { readdirSync, existsSync } from 'fs';
import blocks from './umi-block.json';

const blockHash = {} as any;
blocks.list.forEach((item) => {
blockHash[item.key] = item;
});

export default (api: IApi) => {
api.modifyTSConfig((memo) => {
memo.compilerOptions.paths['umi'] = memo.compilerOptions.paths['@umijs/max'];
return memo;
});
if (api.name !== 'dev') return;
console.log(api.args);
const { _ } = api.args;
// 取巧,没传代表全部
const [name = ''] = _;
const [page = ''] = _;
const components = readdirSync(api.cwd).filter((componentsPath) => {
if (existsSync(join(componentsPath, 'package.json')) && componentsPath.includes(name)) {
if (existsSync(join(componentsPath, 'package.json')) && componentsPath.includes(page)) {
return true;
}
return false;
Expand All @@ -24,19 +29,23 @@ export default (api: IApi) => {
};
return memo;
});
api.modifyRoutes(() => {
let routers = {} as any;
api.modifyRoutes((memo) => {
components.forEach((pagePath) => {
// 临时调试方便
const path = name ? '/' : pagePath.toLocaleLowerCase();
routers['path'] = {
path,
const path = page ? '/' : pagePath.toLocaleLowerCase();
const { name = 'haha' } = blockHash[pagePath];
memo[path] = {
path: `/${path}`,
id: path,
icon: 'smile',
name,
component: join(api.cwd, pagePath, './src/index'),
parentId: 'ant-design-pro-layout',
file: join(api.cwd, pagePath, './src/index'),
absPath: join(api.cwd, pagePath, './src/index'),
absPath: `/${path}`,
__absFile: join(api.cwd, pagePath, './src/index'),
};
});
return routers;
return memo;
});
};

0 comments on commit ff69235

Please sign in to comment.