diff --git a/examples/base/.kktrc.ts b/examples/base/.kktrc.ts index 198699f4d..60069f9df 100644 --- a/examples/base/.kktrc.ts +++ b/examples/base/.kktrc.ts @@ -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')] } }, diff --git a/examples/base/src/layouts/BasicLayout.tsx b/examples/base/src/layouts/BasicLayout.tsx index b53144aae..050dd9402 100644 --- a/examples/base/src/layouts/BasicLayout.tsx +++ b/examples/base/src/layouts/BasicLayout.tsx @@ -27,7 +27,7 @@ function BasicLayoutScreen(props: BasicLayoutProps = { routes: [] }) { }) const basicLayoutProps = { - onReloadAuth: run, + onReloadAuth: () => run(), routes: routes, menus: [ { diff --git a/package.json b/package.json index fe3805382..a63761328 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": [ diff --git a/packages/basic-layouts/src/HeaderRightMenu/index.tsx b/packages/basic-layouts/src/HeaderRightMenu/index.tsx index be67b6887..5fcc6777f 100644 --- a/packages/basic-layouts/src/HeaderRightMenu/index.tsx +++ b/packages/basic-layouts/src/HeaderRightMenu/index.tsx @@ -47,7 +47,7 @@ export default function HeaderRightMenu(props: HeaderRightProps) { { title: '刷新权限', icon: "reload", - onClick: onReloadAuth?.(), + onClick: () => onReloadAuth(), }, { title: '修改密码', diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index 548fd9af7..7642e2504 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -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 } 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) => { @@ -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; } } diff --git a/packages/config/src/uitls.ts b/packages/config/src/uitls.ts new file mode 100644 index 000000000..570b9fcd2 --- /dev/null +++ b/packages/config/src/uitls.ts @@ -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 +} \ No newline at end of file diff --git a/packages/router-control/src/index.tsx b/packages/router-control/src/index.tsx index fe8fa38b1..ff2d20c69 100644 --- a/packages/router-control/src/index.tsx +++ b/packages/router-control/src/index.tsx @@ -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 + return } else if (routeType === "browser") { - return + return } - return + return }