Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 1b9120f1
authored
Jan 22, 2026
by
Lin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: 依赖组件库导入优化
1 parent
9949661e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
204 deletions
apps/web/venus-agentic/venus-agentic-assisant/src/main.ts
apps/web/venus-agentic/venus-agentic-assisant/vite.config.ts
apps/web/venus-agentic/venus-agentic-base/src/main.ts
apps/web/venus-agentic/venus-agentic-base/vite.config.ts
apps/web/venus-agentic/venus-agentic-assisant/src/main.ts
View file @
1b9120f
...
@@ -9,6 +9,7 @@ import {
...
@@ -9,6 +9,7 @@ import {
qiankunWindow
,
qiankunWindow
,
renderWithQiankun
,
renderWithQiankun
,
}
from
'vite-plugin-qiankun/dist/helper'
;
}
from
'vite-plugin-qiankun/dist/helper'
;
import
CommonUI
from
'@venus/common-ui-vue'
;
import
App
from
'./App.vue'
;
import
App
from
'./App.vue'
;
import
{
createRouter
}
from
'./router'
;
import
{
createRouter
}
from
'./router'
;
...
@@ -28,6 +29,9 @@ async function render(props: QiankunProps = {}) {
...
@@ -28,6 +29,9 @@ async function render(props: QiankunProps = {}) {
app
=
createApp
(
App
);
app
=
createApp
(
App
);
// 注册通用 UI 组件库
app
.
use
(
CommonUI
);
// 配置 Pinia
// 配置 Pinia
app
.
use
(
createPinia
());
app
.
use
(
createPinia
());
...
...
apps/web/venus-agentic/venus-agentic-assisant/vite.config.ts
View file @
1b9120f
...
@@ -19,39 +19,18 @@ const __dirname = dirname(__filename);
...
@@ -19,39 +19,18 @@ const __dirname = dirname(__filename);
const
PORT
=
8081
;
const
PORT
=
8081
;
const
APP_NAME
=
"assisant"
;
// 与基座配置的 name 一致
const
APP_NAME
=
"assisant"
;
// 与基座配置的 name 一致
// 获取源码路径
const
commonUiSourcePath
=
resolve
(
__dirname
,
"../../../../packages/common-ui/vue-ui/src/index.ts"
,
);
const
toolsSourcePath
=
resolve
(
const
toolsSourcePath
=
resolve
(
__dirname
,
__dirname
,
"../../../../packages/tools/src"
,
"../../../../packages/tools/src"
,
);
);
// 自定义插件:强制解析 workspace 包
// 自定义插件:强制解析
@venus/tools
workspace 包
function
resolveWorkspacePackage
():
Plugin
{
function
resolveWorkspacePackage
():
Plugin
{
return
{
return
{
name
:
"resolve-workspace-package"
,
name
:
"resolve-workspace-package"
,
enforce
:
"pre"
,
// 在其他插件之前执行
enforce
:
"pre"
,
// 在其他插件之前执行
resolveId
(
id
,
importer
)
{
resolveId
(
id
,
importer
)
{
// 解析 @venus/common-ui-vue
if
(
id
===
"@venus/common-ui-vue"
||
id
.
startsWith
(
"@venus/common-ui-vue/"
)
)
{
// 验证文件是否存在
if
(
existsSync
(
commonUiSourcePath
))
{
return
{
id
:
commonUiSourcePath
,
external
:
false
,
};
}
console
.
warn
(
`[resolve-workspace-package] 文件不存在:
${
commonUiSourcePath
}
`
,
);
}
// 解析 @venus/tools
// 解析 @venus/tools
if
(
id
.
startsWith
(
"@venus/tools/"
))
{
if
(
id
.
startsWith
(
"@venus/tools/"
))
{
const
subPath
=
id
.
replace
(
"@venus/tools/"
,
""
);
const
subPath
=
id
.
replace
(
"@venus/tools/"
,
""
);
...
@@ -177,23 +156,10 @@ export default defineConfig(({ mode, command }) => {
...
@@ -177,23 +156,10 @@ export default defineConfig(({ mode, command }) => {
}),
}),
],
],
resolve
:
{
resolve
:
{
alias
:
[
alias
:
{
{
"@"
:
resolve
(
__dirname
,
"src"
),
find
:
"@"
,
"@public"
:
resolve
(
__dirname
,
"public"
),
replacement
:
resolve
(
__dirname
,
"src"
),
},
},
{
find
:
"@public"
,
replacement
:
resolve
(
__dirname
,
"public"
),
},
{
find
:
"@venus/common-ui-vue"
,
replacement
:
resolve
(
__dirname
,
"../../../../packages/common-ui/vue-ui/src/index.ts"
,
),
},
],
// 设置条件导出优先使用 development
// 设置条件导出优先使用 development
conditions
:
[
"development"
,
"module"
,
"import"
,
"default"
],
conditions
:
[
"development"
,
"module"
,
"import"
,
"default"
],
},
},
...
...
apps/web/venus-agentic/venus-agentic-base/src/main.ts
View file @
1b9120f
import
{
createApp
}
from
'vue'
;
import
{
createApp
}
from
"vue"
;
import
{
createPinia
}
from
'pinia'
;
import
App
from
'./App.vue'
;
import
CommonUI
from
"@venus/common-ui-vue"
;
import
{
fetchConfig
}
from
'./config/center'
;
import
{
setupQiankun
}
from
'./qiankun'
;
import
{
createPinia
}
from
"pinia"
;
import
router
,
{
loadDynamicRoutes
}
from
'./router'
;
import
{
useAppStore
,
useUserStore
}
from
'./stores'
;
import
App
from
"./App.vue"
;
import
{
getToken
}
from
'./utils/auth'
;
import
{
fetchConfig
}
from
"./config/center"
;
import
{
auth
}
from
'./directives/auth'
;
import
{
auth
}
from
"./directives/auth"
;
import
'./styles/element/index.scss'
;
import
{
setupQiankun
}
from
"./qiankun"
;
import
'element-plus/dist/index.css'
;
import
router
,
{
loadDynamicRoutes
}
from
"./router"
;
import
'./style.css'
;
import
{
useAppStore
,
useUserStore
}
from
"./stores"
;
import
{
getToken
}
from
"./utils/auth"
;
import
"./styles/element/index.scss"
;
import
"element-plus/dist/index.css"
;
import
"./style.css"
;
// 创建应用实例
// 创建应用实例
const
app
=
createApp
(
App
);
const
app
=
createApp
(
App
);
// 注册通用 UI 组件库
app
.
use
(
CommonUI
);
// 注册权限指令
// 注册权限指令
app
.
directive
(
'auth'
,
auth
);
app
.
directive
(
"auth"
,
auth
);
// 创建 pinia 实例
// 创建 pinia 实例
const
pinia
=
createPinia
();
const
pinia
=
createPinia
();
...
@@ -27,73 +35,73 @@ app.use(router);
...
@@ -27,73 +35,73 @@ app.use(router);
// 应用初始化
// 应用初始化
async
function
initApp
()
{
async
function
initApp
()
{
try
{
try
{
// 初始化应用状态
// 初始化应用状态
const
appStore
=
useAppStore
();
const
appStore
=
useAppStore
();
appStore
.
initApp
();
appStore
.
initApp
();
// 如果有 token,尝试恢复用户信息
// 如果有 token,尝试恢复用户信息
const
token
=
getToken
();
const
token
=
getToken
();
if
(
token
)
{
if
(
token
)
{
const
userStore
=
useUserStore
();
const
userStore
=
useUserStore
();
userStore
.
setTokenValue
(
token
);
userStore
.
setTokenValue
(
token
);
// 尝试获取用户信息(如果失败,路由守卫会处理)
// 尝试获取用户信息(如果失败,路由守卫会处理)
try
{
try
{
await
userStore
.
getUserInfo
();
await
userStore
.
getUserInfo
();
// 用户信息获取成功后,加载动态路由和菜单-性能优化层(预加载)- 有必要性
// 用户信息获取成功后,加载动态路由和菜单-性能优化层(预加载)- 有必要性
await
loadDynamicRoutes
();
await
loadDynamicRoutes
();
}
catch
{
}
catch
{
// console.warn('[基座] 用户信息恢复失败,将在路由守卫中重新登录');
// console.warn('[基座] 用户信息恢复失败,将在路由守卫中重新登录');
}
}
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
'[基座] 应用初始化失败:'
,
error
);
console
.
error
(
"[基座] 应用初始化失败:"
,
error
);
}
}
}
}
// 监听用户 Store 变化,自动同步到 qiankun 全局状态
// 监听用户 Store 变化,自动同步到 qiankun 全局状态
function
setupStoreSync
()
{
function
setupStoreSync
()
{
const
userStore
=
useUserStore
();
const
userStore
=
useUserStore
();
const
appStore
=
useAppStore
();
const
appStore
=
useAppStore
();
// 监听用户信息变化
// 监听用户信息变化
userStore
.
$subscribe
(()
=>
{
userStore
.
$subscribe
(()
=>
{
// 每次 Store 变化时,同步用户信息
// 每次 Store 变化时,同步用户信息
userStore
.
syncUserToQiankun
();
userStore
.
syncUserToQiankun
();
});
});
// 监听主题变化,同步到 qiankun 全局状态
// 监听主题变化,同步到 qiankun 全局状态
appStore
.
$subscribe
((
_mutation
,
state
)
=>
{
appStore
.
$subscribe
((
_mutation
,
state
)
=>
{
import
(
'./qiankun/communication'
).
then
(({
communicationManager
})
=>
{
import
(
"./qiankun/communication"
).
then
(({
communicationManager
})
=>
{
communicationManager
.
updateTheme
({
communicationManager
.
updateTheme
({
mode
:
state
.
theme
,
mode
:
state
.
theme
,
primaryColor
:
state
.
theme
===
'dark'
?
'#177ddc'
:
'#1890ff'
,
primaryColor
:
state
.
theme
===
"dark"
?
"#177ddc"
:
"#1890ff"
,
});
});
});
});
});
});
}
}
// 获取配置中心配置
// 获取配置中心配置
fetchConfig
()
fetchConfig
()
.
then
((
config
)
=>
{
.
then
((
config
)
=>
{
console
.
log
(
'[基座] 当前配置数据:'
,
config
);
console
.
log
(
"[基座] 当前配置数据:"
,
config
);
})
})
.
catch
((
error
)
=>
{
.
catch
((
error
)
=>
{
console
.
error
(
'[基座] 配置中心配置获取失败:'
,
error
);
console
.
error
(
"[基座] 配置中心配置获取失败:"
,
error
);
})
})
.
finally
(()
=>
{
.
finally
(()
=>
{
// 初始化应用
// 初始化应用
initApp
().
then
(()
=>
{
initApp
().
then
(()
=>
{
// 挂载应用
// 挂载应用
app
.
mount
(
'#app'
);
app
.
mount
(
"#app"
);
// 设置 Store 同步机制
// 设置 Store 同步机制
setupStoreSync
();
setupStoreSync
();
// 等待路由准备就绪后再启动 qiankun,避免刷新时容器未挂载的问题
// 等待路由准备就绪后再启动 qiankun,避免刷新时容器未挂载的问题
router
.
isReady
().
then
(()
=>
{
router
.
isReady
().
then
(()
=>
{
// 启动 qiankun 微前端框架
// 启动 qiankun 微前端框架
setupQiankun
();
setupQiankun
();
});
});
});
});
});
});
apps/web/venus-agentic/venus-agentic-base/vite.config.ts
View file @
1b9120f
import
type
{
Plugin
}
from
'vite'
;
import
{
dirname
,
resolve
}
from
"node:path"
;
import
{
fileURLToPath
}
from
"node:url"
;
import
{
existsSync
}
from
'node:fs'
;
import
vue
from
"@vitejs/plugin-vue"
;
import
{
resolve
}
from
'node:path'
;
import
vueJsx
from
"@vitejs/plugin-vue-jsx"
;
import
AutoImport
from
"unplugin-auto-import/vite"
;
import
{
ElementPlusResolver
}
from
"unplugin-vue-components/resolvers"
;
import
Components
from
"unplugin-vue-components/vite"
;
import
{
defineConfig
}
from
"vite"
;
import
vue
from
'@vitejs/plugin-vue'
;
// 获取 __dirname 的 ES 模块兼容方式
import
vueJsx
from
'@vitejs/plugin-vue-jsx'
;
const
__filename
=
fileURLToPath
(
import
.
meta
.
url
);
import
AutoImport
from
'unplugin-auto-import/vite'
;
const
__dirname
=
dirname
(
__filename
);
import
{
ElementPlusResolver
}
from
'unplugin-vue-components/resolvers'
;
import
Components
from
'unplugin-vue-components/vite'
;
import
{
defineConfig
}
from
'vite'
;
// 获取源码路径
const
commonUiSourcePath
=
resolve
(
__dirname
,
'../../../../packages/common-ui/vue-ui/src/index.ts'
,
);
// 自定义插件:强制解析 @venus/common-ui-vue
function
resolveWorkspacePackage
():
Plugin
{
return
{
name
:
'resolve-workspace-package'
,
enforce
:
'pre'
,
// 在其他插件之前执行
resolveId
(
id
,
importer
)
{
// 精确匹配包名
if
(
id
===
'@venus/common-ui-vue'
||
id
.
startsWith
(
'@venus/common-ui-vue/'
)
)
{
// 验证文件是否存在
if
(
existsSync
(
commonUiSourcePath
))
{
return
{
id
:
commonUiSourcePath
,
external
:
false
,
};
}
console
.
warn
(
`[resolve-workspace-package] 文件不存在:
${
commonUiSourcePath
}
`
,
);
}
return
null
;
},
};
}
export
default
defineConfig
({
export
default
defineConfig
({
plugins
:
[
plugins
:
[
resolveWorkspacePackage
(),
vue
(),
vue
(),
vueJsx
(),
vueJsx
(),
AutoImport
({
AutoImport
({
imports
:
[
"vue"
,
"vue-router"
,
"pinia"
],
imports
:
[
'vue'
,
'vue-router'
,
'pinia'
],
resolvers
:
[
ElementPlusResolver
()
],
resolvers
:
[
ElementPlusResolver
()],
dts
:
"src/auto-imports.d.ts"
,
dts
:
'src/auto-imports.d.ts'
,
}),
}),
Components
({
Components
({
resolvers
:
[
ElementPlusResolver
()
],
resolvers
:
[
ElementPlusResolver
()],
dts
:
"src/components.d.ts"
,
dts
:
'src/components.d.ts'
,
}),
}),
],
],
resolve
:
{
resolve
:
{
alias
:
{
alias
:
[
"@"
:
resolve
(
__dirname
,
"src"
),
{
},
find
:
'@'
,
// 配置条件导出优先级,让打包时也使用 development 模式的源码
replacement
:
resolve
(
__dirname
,
'src'
),
conditions
:
[
"development"
,
"module"
,
"import"
,
"default"
],
},
},
{
// 优化依赖预构建,排除 workspace 包
find
:
'@venus/common-ui-vue'
,
optimizeDeps
:
{
replacement
:
resolve
(
exclude
:
[
"@venus/common-ui-vue"
],
__dirname
,
include
:
[],
'../../../../packages/common-ui/vue-ui/src/index.ts'
,
},
),
server
:
{
},
port
:
8080
,
],
cors
:
true
,
// 设置条件导出优先使用 development
host
:
true
,
conditions
:
[
'development'
,
'module'
,
'import'
,
'default'
],
},
},
build
:
{
// 优化依赖预构建,排除 workspace 包
target
:
"esnext"
,
optimizeDeps
:
{
minify
:
false
,
exclude
:
[
'@venus/common-ui-vue'
],
cssCodeSplit
:
false
,
include
:
[],
},
},
server
:
{
port
:
8080
,
cors
:
true
,
host
:
true
,
},
build
:
{
target
:
'esnext'
,
minify
:
false
,
cssCodeSplit
:
false
,
},
});
});
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment