2023-01-06 23:10:33 +08:00
|
|
|
import {
|
|
|
|
|
fileURLToPath,
|
|
|
|
|
URL
|
|
|
|
|
} from 'node:url'
|
|
|
|
|
import {
|
|
|
|
|
defineConfig,
|
|
|
|
|
loadEnv
|
|
|
|
|
} from 'vite'
|
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
|
|
|
import Components from 'unplugin-vue-components/vite'
|
|
|
|
|
import {
|
|
|
|
|
NaiveUiResolver
|
|
|
|
|
} from 'unplugin-vue-components/resolvers'
|
2023-01-15 20:34:13 +08:00
|
|
|
import {
|
|
|
|
|
VitePWA
|
|
|
|
|
} from 'vite-plugin-pwa'
|
2023-01-06 23:10:33 +08:00
|
|
|
|
|
|
|
|
// https://vitejs.dev/config/
|
|
|
|
|
export default ({
|
|
|
|
|
mode
|
|
|
|
|
}) => defineConfig({
|
|
|
|
|
plugins: [vue(), AutoImport({
|
|
|
|
|
imports: [
|
|
|
|
|
'vue',
|
|
|
|
|
{
|
|
|
|
|
'naive-ui': [
|
|
|
|
|
'useDialog',
|
|
|
|
|
'useMessage',
|
|
|
|
|
'useNotification',
|
|
|
|
|
'useLoadingBar'
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}),
|
|
|
|
|
Components({
|
|
|
|
|
resolvers: [NaiveUiResolver()]
|
2023-01-15 20:34:13 +08:00
|
|
|
}),
|
|
|
|
|
// PWA
|
|
|
|
|
VitePWA({
|
|
|
|
|
registerType: 'autoUpdate',
|
|
|
|
|
devOptions: {
|
|
|
|
|
enabled: true
|
|
|
|
|
},
|
|
|
|
|
workbox: {
|
2023-02-03 11:18:39 +08:00
|
|
|
cleanupOutdatedCaches: true,
|
2023-01-15 20:34:13 +08:00
|
|
|
runtimeCaching: [{
|
2023-02-03 11:18:39 +08:00
|
|
|
urlPattern: /(.*?)\.(woff2|woff|ttf)/,
|
2023-01-15 20:34:13 +08:00
|
|
|
handler: 'CacheFirst',
|
|
|
|
|
options: {
|
|
|
|
|
cacheName: 'file-cache',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
urlPattern: /(.*?)\.(webp|png|jpe?g|svg|gif|bmp|psd|tiff|tga|eps)/,
|
|
|
|
|
handler: 'CacheFirst',
|
|
|
|
|
options: {
|
|
|
|
|
cacheName: 'image-cache',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
manifest: {
|
|
|
|
|
"name": "SPlayer",
|
|
|
|
|
"short_name": "SPlayer",
|
|
|
|
|
"description": "一个简约的在线音乐播放器",
|
|
|
|
|
"display": "standalone",
|
|
|
|
|
"start_url": "/",
|
|
|
|
|
"theme_color": "#f55e55",
|
|
|
|
|
"background_color": "#efefef",
|
|
|
|
|
"icons": [{
|
|
|
|
|
"src": "/images/logo/favicon.png",
|
|
|
|
|
"sizes": "200x200",
|
|
|
|
|
"type": "image/png"
|
|
|
|
|
}]
|
|
|
|
|
}
|
2023-01-06 23:10:33 +08:00
|
|
|
})
|
|
|
|
|
],
|
|
|
|
|
server: {
|
|
|
|
|
port: 2048,
|
|
|
|
|
open: true,
|
|
|
|
|
http: true,
|
|
|
|
|
ssr: false,
|
|
|
|
|
proxy: {
|
|
|
|
|
'/api': {
|
|
|
|
|
target: loadEnv(mode, process.cwd()).VITE_MUSIC_API,
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
rewrite: path => path.replace(/^\/api/, '')
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
css: {
|
|
|
|
|
preprocessorOptions: {
|
|
|
|
|
scss: {
|
|
|
|
|
additionalData: '@import "src/style/index.scss";'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
'@': fileURLToPath(new URL('./src',
|
|
|
|
|
import.meta.url))
|
|
|
|
|
}
|
2023-01-14 10:59:15 +08:00
|
|
|
},
|
|
|
|
|
build: {
|
|
|
|
|
minify: 'terser',
|
|
|
|
|
terserOptions: {
|
|
|
|
|
compress: {
|
|
|
|
|
// 生产环境时移除 console
|
|
|
|
|
pure_funcs: ['console.log'],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-01-06 23:10:33 +08:00
|
|
|
})
|