2022-06-16 10:42:13 +00:00
|
|
|
import { fileURLToPath, URL } from "url";
|
|
|
|
|
|
|
|
import { defineConfig } from "vite";
|
|
|
|
import Vue from "@vitejs/plugin-vue";
|
|
|
|
import VueJsx from "@vitejs/plugin-vue-jsx";
|
|
|
|
import path from "path";
|
|
|
|
import Dts from "vite-plugin-dts";
|
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
plugins: [
|
|
|
|
Vue(),
|
|
|
|
VueJsx(),
|
|
|
|
Dts({
|
|
|
|
entryRoot: "./src",
|
|
|
|
outputDir: "./dist",
|
|
|
|
insertTypesEntry: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
build: {
|
|
|
|
outDir: path.resolve(__dirname, "dist"),
|
|
|
|
lib: {
|
|
|
|
entry: path.resolve(__dirname, "src/index.ts"),
|
2022-10-09 06:56:33 +00:00
|
|
|
name: "HaloConsoleShared",
|
2022-07-21 07:03:30 +00:00
|
|
|
formats: ["es", "iife"],
|
2022-10-09 06:56:33 +00:00
|
|
|
fileName: (format) => `halo-console-shared.${format}.js`,
|
2022-06-16 10:42:13 +00:00
|
|
|
},
|
|
|
|
rollupOptions: {
|
refactor: router and menu generation (#651)
#### What type of PR is this?
/kind api-change
/kind improvement
/milestone 2.0
#### What this PR does / why we need it:
Ref https://github.com/halo-dev/halo/issues/2595
重构路由和侧边菜单生成的逻辑,**注意,此 PR 对插件的 Console 入口文件中的路由和菜单定义包含破坏性更新。**
1. 移除 `definePlugin` 方法的 `menus` 字段,改为在 route 的 meta 中定义。
2. 将 `RoutesMenu` 组件从 `@halo-dev/components` 包中移出。
3. 将 `BasicLayout` 组件从 `@halo-dev/console-shared` 包中移出。
定义路由的方式:
```ts
import { definePlugin } from "@halo-dev/console-shared";
import BasicLayout from "@/layouts/BasicLayout.vue";
import AttachmentList from "./AttachmentList.vue";
import AttachmentSelectorModal from "./components/AttachmentSelectorModal.vue";
import { IconFolder } from "@halo-dev/components";
import { markRaw } from "vue";
export default definePlugin({
name: "attachmentModule",
components: [AttachmentSelectorModal],
routes: [
{
path: "/attachments",
component: BasicLayout,
children: [
{
path: "",
name: "Attachments",
component: AttachmentList,
meta: {
title: "附件",
permissions: ["system:attachments:view"],
menu: {
name: "附件",
group: "内容",
icon: markRaw(IconFolder),
priority: 4,
mobile: true,
},
},
},
],
},
],
});
```
menu 字段类型:
```ts
interface RouteMeta {
title?: string;
searchable?: boolean;
permissions?: string[];
menu?: {
name: string;
group?: string;
icon?: Component;
priority: number;
mobile?: true;
};
}
```
插件适配需要做的改动:
1. 移除 `definePlugin` 中的 menus 字段。
2. 在需要添加到菜单的 route 中提供 `meta.menu` 对象,可参考上方的 menu 字段类型。
详细文档可查阅:https://github.com/ruibaby/halo-console/tree/refactor/route-map-setting/docs/routes-generation
todolist:
- [x] 完善预设的菜单分组定义。
- [x] 绑定权限,根据权限决定是否需要将路由添加到菜单。
- [x] 优化菜单排序的定义方式。
#### Which issue(s) this PR fixes:
Fixes https://github.com/halo-dev/halo/issues/2595
#### Special notes for your reviewer:
/cc @halo-dev/sig-halo-console
测试方式:
1. 需要 `pnpm build:packages`
2. 测试后台的菜单及路由是否有异常。
3. 新建角色测试路由和菜单对权限的绑定。
4. 按照 https://github.com/ruibaby/halo-console/tree/refactor/route-map-setting/docs/routes-generation 文档,创建插件,测试插件添加路由和菜单是否正常。
#### Does this PR introduce a user-facing change?
```release-note
重构路由和侧边菜单生成的逻辑。
```
2022-10-19 08:54:13 +00:00
|
|
|
external: ["vue", "vue-router"],
|
2022-06-16 10:42:13 +00:00
|
|
|
output: {
|
|
|
|
globals: {
|
|
|
|
vue: "Vue",
|
|
|
|
"vue-router": "VueRouter",
|
|
|
|
},
|
|
|
|
exports: "named",
|
2022-08-09 04:05:40 +00:00
|
|
|
generatedCode: "es5",
|
2022-06-16 10:42:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
sourcemap: true,
|
|
|
|
},
|
|
|
|
});
|