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 {
qiankunWindow
,
renderWithQiankun
,
}
from
'vite-plugin-qiankun/dist/helper'
;
import
CommonUI
from
'@venus/common-ui-vue'
;
import
App
from
'./App.vue'
;
import
{
createRouter
}
from
'./router'
;
...
...
@@ -28,6 +29,9 @@ async function render(props: QiankunProps = {}) {
app
=
createApp
(
App
);
// 注册通用 UI 组件库
app
.
use
(
CommonUI
);
// 配置 Pinia
app
.
use
(
createPinia
());
...
...
apps/web/venus-agentic/venus-agentic-assisant/vite.config.ts
View file @
1b9120f
...
...
@@ -19,39 +19,18 @@ const __dirname = dirname(__filename);
const
PORT
=
8081
;
const
APP_NAME
=
"assisant"
;
// 与基座配置的 name 一致
// 获取源码路径
const
commonUiSourcePath
=
resolve
(
__dirname
,
"../../../../packages/common-ui/vue-ui/src/index.ts"
,
);
const
toolsSourcePath
=
resolve
(
__dirname
,
"../../../../packages/tools/src"
,
);
// 自定义插件:强制解析 workspace 包
// 自定义插件:强制解析
@venus/tools
workspace 包
function
resolveWorkspacePackage
():
Plugin
{
return
{
name
:
"resolve-workspace-package"
,
enforce
:
"pre"
,
// 在其他插件之前执行
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
if
(
id
.
startsWith
(
"@venus/tools/"
))
{
const
subPath
=
id
.
replace
(
"@venus/tools/"
,
""
);
...
...
@@ -177,23 +156,10 @@ export default defineConfig(({ mode, command }) => {
}),
],
resolve
:
{
alias
:
[
{
find
:
"@"
,
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"
,
),
},
],
alias
:
{
"@"
:
resolve
(
__dirname
,
"src"
),
"@public"
:
resolve
(
__dirname
,
"public"
),
},
// 设置条件导出优先使用 development
conditions
:
[
"development"
,
"module"
,
"import"
,
"default"
],
},
...
...
apps/web/venus-agentic/venus-agentic-base/src/main.ts
View file @
1b9120f
import
{
createApp
}
from
'vue'
;
import
{
createPinia
}
from
'pinia'
;
import
App
from
'./App.vue'
;
import
{
fetchConfig
}
from
'./config/center'
;
import
{
setupQiankun
}
from
'./qiankun'
;
import
router
,
{
loadDynamicRoutes
}
from
'./router'
;
import
{
useAppStore
,
useUserStore
}
from
'./stores'
;
import
{
getToken
}
from
'./utils/auth'
;
import
{
auth
}
from
'./directives/auth'
;
import
'./styles/element/index.scss'
;
import
'element-plus/dist/index.css'
;
import
'./style.css'
;
import
{
createApp
}
from
"vue"
;
import
CommonUI
from
"@venus/common-ui-vue"
;
import
{
createPinia
}
from
"pinia"
;
import
App
from
"./App.vue"
;
import
{
fetchConfig
}
from
"./config/center"
;
import
{
auth
}
from
"./directives/auth"
;
import
{
setupQiankun
}
from
"./qiankun"
;
import
router
,
{
loadDynamicRoutes
}
from
"./router"
;
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
);
// 注册通用 UI 组件库
app
.
use
(
CommonUI
);
// 注册权限指令
app
.
directive
(
'auth'
,
auth
);
app
.
directive
(
"auth"
,
auth
);
// 创建 pinia 实例
const
pinia
=
createPinia
();
...
...
@@ -27,73 +35,73 @@ app.use(router);
// 应用初始化
async
function
initApp
()
{
try
{
// 初始化应用状态
const
appStore
=
useAppStore
();
appStore
.
initApp
();
// 如果有 token,尝试恢复用户信息
const
token
=
getToken
();
if
(
token
)
{
const
userStore
=
useUserStore
();
userStore
.
setTokenValue
(
token
);
// 尝试获取用户信息(如果失败,路由守卫会处理)
try
{
await
userStore
.
getUserInfo
();
// 用户信息获取成功后,加载动态路由和菜单-性能优化层(预加载)- 有必要性
await
loadDynamicRoutes
();
}
catch
{
// console.warn('[基座] 用户信息恢复失败,将在路由守卫中重新登录');
}
}
}
catch
(
error
)
{
console
.
error
(
'[基座] 应用初始化失败:'
,
error
);
}
try
{
// 初始化应用状态
const
appStore
=
useAppStore
();
appStore
.
initApp
();
// 如果有 token,尝试恢复用户信息
const
token
=
getToken
();
if
(
token
)
{
const
userStore
=
useUserStore
();
userStore
.
setTokenValue
(
token
);
// 尝试获取用户信息(如果失败,路由守卫会处理)
try
{
await
userStore
.
getUserInfo
();
// 用户信息获取成功后,加载动态路由和菜单-性能优化层(预加载)- 有必要性
await
loadDynamicRoutes
();
}
catch
{
// console.warn('[基座] 用户信息恢复失败,将在路由守卫中重新登录');
}
}
}
catch
(
error
)
{
console
.
error
(
"[基座] 应用初始化失败:"
,
error
);
}
}
// 监听用户 Store 变化,自动同步到 qiankun 全局状态
function
setupStoreSync
()
{
const
userStore
=
useUserStore
();
const
appStore
=
useAppStore
();
// 监听用户信息变化
userStore
.
$subscribe
(()
=>
{
// 每次 Store 变化时,同步用户信息
userStore
.
syncUserToQiankun
();
});
// 监听主题变化,同步到 qiankun 全局状态
appStore
.
$subscribe
((
_mutation
,
state
)
=>
{
import
(
'./qiankun/communication'
).
then
(({
communicationManager
})
=>
{
communicationManager
.
updateTheme
({
mode
:
state
.
theme
,
primaryColor
:
state
.
theme
===
'dark'
?
'#177ddc'
:
'#1890ff'
,
});
});
});
const
userStore
=
useUserStore
();
const
appStore
=
useAppStore
();
// 监听用户信息变化
userStore
.
$subscribe
(()
=>
{
// 每次 Store 变化时,同步用户信息
userStore
.
syncUserToQiankun
();
});
// 监听主题变化,同步到 qiankun 全局状态
appStore
.
$subscribe
((
_mutation
,
state
)
=>
{
import
(
"./qiankun/communication"
).
then
(({
communicationManager
})
=>
{
communicationManager
.
updateTheme
({
mode
:
state
.
theme
,
primaryColor
:
state
.
theme
===
"dark"
?
"#177ddc"
:
"#1890ff"
,
});
});
});
}
// 获取配置中心配置
fetchConfig
()
.
then
((
config
)
=>
{
console
.
log
(
'[基座] 当前配置数据:'
,
config
);
})
.
catch
((
error
)
=>
{
console
.
error
(
'[基座] 配置中心配置获取失败:'
,
error
);
})
.
finally
(()
=>
{
// 初始化应用
initApp
().
then
(()
=>
{
// 挂载应用
app
.
mount
(
'#app'
);
// 设置 Store 同步机制
setupStoreSync
();
// 等待路由准备就绪后再启动 qiankun,避免刷新时容器未挂载的问题
router
.
isReady
().
then
(()
=>
{
// 启动 qiankun 微前端框架
setupQiankun
();
});
});
});
.
then
((
config
)
=>
{
console
.
log
(
"[基座] 当前配置数据:"
,
config
);
})
.
catch
((
error
)
=>
{
console
.
error
(
"[基座] 配置中心配置获取失败:"
,
error
);
})
.
finally
(()
=>
{
// 初始化应用
initApp
().
then
(()
=>
{
// 挂载应用
app
.
mount
(
"#app"
);
// 设置 Store 同步机制
setupStoreSync
();
// 等待路由准备就绪后再启动 qiankun,避免刷新时容器未挂载的问题
router
.
isReady
().
then
(()
=>
{
// 启动 qiankun 微前端框架
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
{
resolve
}
from
'node:path'
;
import
vue
from
"@vitejs/plugin-vue"
;
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'
;
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'
;
// 获取源码路径
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
;
},
};
}
// 获取 __dirname 的 ES 模块兼容方式
const
__filename
=
fileURLToPath
(
import
.
meta
.
url
);
const
__dirname
=
dirname
(
__filename
);
export
default
defineConfig
({
plugins
:
[
resolveWorkspacePackage
(),
vue
(),
vueJsx
(),
AutoImport
({
imports
:
[
'vue'
,
'vue-router'
,
'pinia'
],
resolvers
:
[
ElementPlusResolver
()],
dts
:
'src/auto-imports.d.ts'
,
}),
Components
({
resolvers
:
[
ElementPlusResolver
()],
dts
:
'src/components.d.ts'
,
}),
],
resolve
:
{
alias
:
[
{
find
:
'@'
,
replacement
:
resolve
(
__dirname
,
'src'
),
},
{
find
:
'@venus/common-ui-vue'
,
replacement
:
resolve
(
__dirname
,
'../../../../packages/common-ui/vue-ui/src/index.ts'
,
),
},
],
// 设置条件导出优先使用 development
conditions
:
[
'development'
,
'module'
,
'import'
,
'default'
],
},
// 优化依赖预构建,排除 workspace 包
optimizeDeps
:
{
exclude
:
[
'@venus/common-ui-vue'
],
include
:
[],
},
server
:
{
port
:
8080
,
cors
:
true
,
host
:
true
,
},
build
:
{
target
:
'esnext'
,
minify
:
false
,
cssCodeSplit
:
false
,
},
plugins
:
[
vue
(),
vueJsx
(),
AutoImport
({
imports
:
[
"vue"
,
"vue-router"
,
"pinia"
],
resolvers
:
[
ElementPlusResolver
()
],
dts
:
"src/auto-imports.d.ts"
,
}),
Components
({
resolvers
:
[
ElementPlusResolver
()
],
dts
:
"src/components.d.ts"
,
}),
],
resolve
:
{
alias
:
{
"@"
:
resolve
(
__dirname
,
"src"
),
},
// 配置条件导出优先级,让打包时也使用 development 模式的源码
conditions
:
[
"development"
,
"module"
,
"import"
,
"default"
],
},
// 优化依赖预构建,排除 workspace 包
optimizeDeps
:
{
exclude
:
[
"@venus/common-ui-vue"
],
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