Skip to content

Commit

Permalink
fix:修改@uiw-admin/config包
Browse files Browse the repository at this point in the history
  • Loading branch information
SunLxy committed Jan 16, 2022
1 parent 4bb0e3a commit 5644cce
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 11 deletions.
2 changes: 2 additions & 0 deletions examples/base/.kktrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import defaultConfig from "@uiw-admin/config"
export default defaultConfig({
define: {
VERSION: JSON.stringify(pkg.version),
// BASE_NAME: "/uiw"
},
// publicPath: process.env.NODE_ENV === "development" ? "/" : "/uiw/",
loader: [
rawModules,
{ loader: scopePluginOptions, options: { allowedFiles: [path.resolve(process.cwd(), 'README.md')] } },
Expand Down
2 changes: 1 addition & 1 deletion examples/base/src/layouts/BasicLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function BasicLayoutScreen(props: BasicLayoutProps = { routes: [] }) {
})

const basicLayoutProps = {
onReloadAuth: run,
onReloadAuth: () => run(),
routes: routes,
menus: [
{
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"author": "jaywcjlove",
"license": "MIT",
"dependencies": {
"@uiw/react-menu": "4.9.7",
"@babel/core": "7.16.7",
"husky": "7.0.4",
"lerna": "4.0.0",
Expand All @@ -70,7 +69,8 @@
"kkt": "7.0.5"
},
"resolutions": {
"@uiw/react-menu": "4.9.7"
"@uiw/react-menu": "4.9.7",
"mini-css-extract-plugin": "2.4.7"
},
"workspaces": {
"packages": [
Expand Down
2 changes: 1 addition & 1 deletion packages/basic-layouts/src/HeaderRightMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function HeaderRightMenu(props: HeaderRightProps) {
{
title: '刷新权限',
icon: "reload",
onClick: onReloadAuth?.(),
onClick: () => onReloadAuth(),
},
{
title: '修改密码',
Expand Down
31 changes: 27 additions & 4 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
import webpack, { Configuration, } from 'webpack';
import { LoaderConfOptions } from 'kkt';
import path from "path"
import { transformationDefineString } from "./uitls"

/** 全局默认公共参数 */
export const defaultDefine = {
/** 权限校验 默认 true */
AUTH: JSON.stringify(true),
/** 路由 跳转前缀 默认 "/" */
BASE_NAME: "/",
BASE_NAME: JSON.stringify("/"),
}
export type ConfFun = (conf: Configuration, evn: string, options?: LoaderConfOptions | undefined) => Configuration

export interface ConfigProps {
/** 别名 */
alias?: { [s: string]: string },
/** 插件 */
plugins?: Configuration["plugins"],
define?: webpack.DefinePlugin["definitions"],
/** 默认全局变量 define , 注意:对象的属性值会经过一次 JSON.stringify 转换 */
define?: { [s: string]: any },
/** 其他 工具 */
loader?: (ConfFun | { loader?: ConfFun, options?: LoaderConfOptions | undefined | { [s: string]: any } })[]
/** 项目前缀 */
publicPath?: string;
/** 更多的 自定义 配置 */
moreConfig?: ConfFun;
/** 输出 */
output?: Omit<Configuration["output"], "publicPath">
}
export default (props: ConfigProps) => {
const { plugins, alias, define, loader: ConfFunArr } = props || {}
const { plugins, alias, define, loader: ConfFunArr, moreConfig, publicPath, output } = props || {}
return (conf: Configuration, env: string, options: LoaderConfOptions) => {
if (ConfFunArr) {
ConfFunArr.forEach((fun) => {
Expand All @@ -32,13 +44,24 @@ export default (props: ConfigProps) => {
conf.plugins!.push(
new webpack.DefinePlugin({
...defaultDefine,
...(define || {}),
...transformationDefineString(define || {}),
}),
...(plugins || [])
);
conf.resolve!.alias = {
...(alias || {}),
};
if (publicPath) {
conf.output = {
/** 添加 publicPath 如果不加 path ,打包会找不到文件报错 */
path: path.resolve(process.cwd(), 'build'),
publicPath,
...(output || {})
}
}
if (moreConfig) {
return moreConfig(conf, env, options)
}
return conf;
}
}
Expand Down
7 changes: 7 additions & 0 deletions packages/config/src/uitls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const transformationDefineString = (obj: { [s: string]: any }) => {
const result: { [s: string]: string } = {}
Object.entries(obj).forEach(([key, value]) => {
result[key] = JSON.stringify(value)
})
return result
}
10 changes: 7 additions & 3 deletions packages/router-control/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,20 @@ export function RouteChild(props: ControllerProps = {}) {

export default function Controller(props: ControllerProps = {}) {
const { routes = [], routeType, basename = "/", addModel } = props;

// @ts-ignore
let base = BASE_NAME || basename

if (routeType === "hash") {
return <HashRouter window={window} basename={basename} >
return <HashRouter window={window} basename={base} >
<RouteChild routes={routes} addModel={addModel} />
</HashRouter>
} else if (routeType === "browser") {
return <BrowserRouter window={window} basename={basename} >
return <BrowserRouter window={window} basename={base} >
<RouteChild routes={routes} addModel={addModel} />
</BrowserRouter>
}
return <HistoryRouter history={history} basename={basename} >
return <HistoryRouter history={history} basename={base} >
<RouteChild routes={routes} addModel={addModel} />
</HistoryRouter>
}

0 comments on commit 5644cce

Please sign in to comment.