Files
SmartisanNote.Remake/vite.config.js
2025-11-03 15:23:25 +08:00

86 lines
2.5 KiB
JavaScript

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { VitePWA } from 'vite-plugin-pwa'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const isPwaMode = mode === 'pwa'
const plugins = [vue()]
// 只在PWA模式下添加PWA插件
if (isPwaMode) {
plugins.push(
VitePWA({
strategies: 'generateSW',
registerType: 'autoUpdate',
devOptions: {
enabled: false,
type: 'module',
},
manifest: {
name: '锤子便签',
short_name: '便签',
description: '锤子便签(重制版)',
theme_color: '#42b883',
start_url: '/',
display: 'standalone',
background_color: '#ffffff',
icons: [
{
src: 'icons/icon-192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: 'icons/icon-512.png',
sizes: '512x512',
type: 'image/png',
},
],
},
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,jpg,jpeg,svg,woff,woff2,ttf,eot}'],
// 预缓存我们指定的静态资源
additionalManifestEntries: [
{ url: '/', revision: null },
{ url: '/index.html', revision: null },
{ url: '/icons/icon-192.png', revision: null },
{ url: '/icons/icon-512.png', revision: null },
// 添加更多需要预缓存的静态资源
{ url: '/assets/icons/drawable-xxhdpi/note_background.png', revision: null },
{ url: '/assets/icons/drawable-xxhdpi/note_setting_bg.png', revision: null },
{ url: '/assets/icons/drawable-xxhdpi/action_bar_default.png', revision: null },
],
},
})
)
}
return {
plugins,
resolve: {
alias: {
'@': '/src',
},
},
server: {
port: 3000,
},
build: {
outDir: isPwaMode ? 'dist/offline' : 'dist/standard',
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
rollupOptions: {
output: {
// 为CSS和JS文件添加哈希后缀
entryFileNames: 'assets/[name].[hash].js',
chunkFileNames: 'assets/[name].[hash].js',
assetFileNames: 'assets/[name].[hash].[ext]',
},
},
},
}
})