Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
corporateCulture-qd
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王立鹏
corporateCulture-qd
Commits
ef38ed4f
Commit
ef38ed4f
authored
Dec 08, 2025
by
lijiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【需求 17679】 feat: 加入更新推送插件
parent
22578cdd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
1 deletions
+75
-1
main.ts
src/main.ts
+6
-0
pushUpdatePlugin.ts
src/plugins/pushUpdatePlugin.ts
+66
-0
vite.config.ts
vite.config.ts
+3
-1
No files found.
src/main.ts
View file @
ef38ed4f
...
@@ -11,6 +11,12 @@ import 'virtual:uno.css'
...
@@ -11,6 +11,12 @@ import 'virtual:uno.css'
import
'virtual:svg-icons-register'
import
'virtual:svg-icons-register'
import
SvgIcon
from
'@/components/common/SvgIcon/svgIcon.vue'
import
SvgIcon
from
'@/components/common/SvgIcon/svgIcon.vue'
import
*
as
ElementPlusIconsVue
from
'@element-plus/icons-vue'
import
*
as
ElementPlusIconsVue
from
'@element-plus/icons-vue'
import
{
loopGetVersion
}
from
'@/plugins/pushUpdatePlugin'
if
(
import
.
meta
.
env
.
MODE
===
'production'
)
{
loopGetVersion
()
}
const
app
=
createApp
(
App
)
const
app
=
createApp
(
App
)
app
.
use
(
createPinia
())
app
.
use
(
createPinia
())
app
.
use
(
router
)
app
.
use
(
router
)
...
...
src/plugins/pushUpdatePlugin.ts
0 → 100644
View file @
ef38ed4f
import
type
{
Plugin
}
from
'vite'
import
fs
from
'node:fs'
import
path
from
'node:path'
export
default
function
pushUpdatePlugin
():
Plugin
{
return
{
name
:
'push-update-plugin'
,
apply
:
'build'
,
writeBundle
(
options
)
{
const
version
=
Date
.
now
().
toString
()
const
outDir
=
options
.
dir
||
path
.
resolve
(
process
.
cwd
(),
'dist'
)
const
filePath
=
path
.
resolve
(
outDir
,
'version.json'
)
fs
.
writeFileSync
(
filePath
,
JSON
.
stringify
({
version
},
null
,
2
),
// 存成 json
'utf-8'
,
)
},
}
}
async
function
getVersion
()
{
const
res
=
await
fetch
(
'/version.json?t='
+
Date
.
now
())
const
data
=
await
res
.
json
()
return
data
.
version
}
export
async
function
loopGetVersion
()
{
const
version
=
await
getVersion
()
let
hasShow
=
false
let
timer
:
NodeJS
.
Timeout
|
null
=
null
timer
=
setInterval
(
async
()
=>
{
const
newVersion
=
await
getVersion
()
if
(
newVersion
===
version
)
return
if
(
hasShow
)
{
if
(
timer
)
{
clearInterval
(
timer
)
}
return
}
ElNotification
({
title
:
'更新提示'
,
type
:
'primary'
,
offset
:
50
,
duration
:
0
,
message
:
()
=>
h
(
'div'
,
{
class
:
'flex items-center'
},
[
'有新版本更新,请'
,
h
(
ElLink
,
{
type
:
'primary'
,
underline
:
false
,
onClick
:
()
=>
{
window
.
location
.
reload
()
},
},
'刷新'
,
),
'页面'
,
]),
})
hasShow
=
true
},
10000
)
}
vite.config.ts
View file @
ef38ed4f
...
@@ -9,6 +9,7 @@ import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
...
@@ -9,6 +9,7 @@ import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import
{
createSvgIconsPlugin
}
from
'vite-plugin-svg-icons'
import
{
createSvgIconsPlugin
}
from
'vite-plugin-svg-icons'
import
{
visualizer
}
from
'rollup-plugin-visualizer'
import
{
visualizer
}
from
'rollup-plugin-visualizer'
import
UnoCSS
from
'unocss/vite'
import
UnoCSS
from
'unocss/vite'
import
pushUpdatePlugin
from
'./src/plugins/pushUpdatePlugin'
import
path
from
'node:path'
import
path
from
'node:path'
...
@@ -46,6 +47,7 @@ export default defineConfig(({ mode }) => {
...
@@ -46,6 +47,7 @@ export default defineConfig(({ mode }) => {
symbolId
:
'icon-[dir]-[name]'
,
symbolId
:
'icon-[dir]-[name]'
,
}),
}),
mode
===
'development'
&&
visualizer
(),
// 开发环境打包才需要
mode
===
'development'
&&
visualizer
(),
// 开发环境打包才需要
pushUpdatePlugin
(),
],
],
server
:
{
server
:
{
// 是否开启 https
// 是否开启 https
...
@@ -70,7 +72,7 @@ export default defineConfig(({ mode }) => {
...
@@ -70,7 +72,7 @@ export default defineConfig(({ mode }) => {
chunkFileNames
:
'assets/js/[name]-[hash].js'
,
chunkFileNames
:
'assets/js/[name]-[hash].js'
,
manualChunks
:
(
id
)
=>
{
manualChunks
:
(
id
)
=>
{
if
(
id
.
includes
(
'node_modules'
))
{
if
(
id
.
includes
(
'node_modules'
))
{
console
.
log
(
id
)
//
console.log(id)
if
(
id
.
includes
(
'element-plus'
))
{
if
(
id
.
includes
(
'element-plus'
))
{
return
'element-plus'
return
'element-plus'
}
else
if
(
id
.
includes
(
'vue'
))
{
}
else
if
(
id
.
includes
(
'vue'
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment