up. 移除workbox-webpack-plugin 包,换vite-plugin-pwa包
This commit is contained in:
parent
8514062951
commit
c02aeec65d
@ -1,3 +1,5 @@
|
|||||||
# 开发环境接口地址
|
# 开发环境接口地址
|
||||||
#VITE_API_URL=https://v2.eleadmin.com/api
|
#VITE_API_URL=https://v2.eleadmin.com/api
|
||||||
VITE_API_URL=http://a.tcp.run/adminapi
|
VITE_API_URL=http://a.tcp.run/adminapi
|
||||||
|
# 禁请求加密
|
||||||
|
VITE_SKIP_REQUEST_ENCRYPTION=1
|
||||||
|
|||||||
@ -47,7 +47,6 @@
|
|||||||
"vue-i18n": "^11.1.11",
|
"vue-i18n": "^11.1.11",
|
||||||
"vue-router": "4.5.1",
|
"vue-router": "4.5.1",
|
||||||
"vuedraggable": "4.1.0",
|
"vuedraggable": "4.1.0",
|
||||||
"workbox-webpack-plugin": "^7.3.0",
|
|
||||||
"xgplayer": "3.0.22",
|
"xgplayer": "3.0.22",
|
||||||
"xgplayer-hls": "^2.5.2",
|
"xgplayer-hls": "^2.5.2",
|
||||||
"xgplayer-music": "3.0.22"
|
"xgplayer-music": "3.0.22"
|
||||||
@ -72,6 +71,7 @@
|
|||||||
"unplugin-vue-components": "28.7.0",
|
"unplugin-vue-components": "28.7.0",
|
||||||
"vite": "6.3.5",
|
"vite": "6.3.5",
|
||||||
"vite-plugin-compression": "0.5.1",
|
"vite-plugin-compression": "0.5.1",
|
||||||
|
"vite-plugin-pwa": "^1.0.3",
|
||||||
"vue-eslint-parser": "9.4.3",
|
"vue-eslint-parser": "9.4.3",
|
||||||
"vue-tsc": "2.2.10"
|
"vue-tsc": "2.2.10"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,4 +38,4 @@ export const LICENSE_CODE = import.meta.env.VITE_LICENSE;
|
|||||||
export const DATA_SECRET_KEY = "mySecretKey123!"
|
export const DATA_SECRET_KEY = "mySecretKey123!"
|
||||||
|
|
||||||
/** 请求加密开关 */
|
/** 请求加密开关 */
|
||||||
export const REQUEST_ENCRYPTION = import.meta.env.REQUEST_ENCRYPTION;
|
export const SKIP_REQUEST_ENCRYPTION = import.meta.env.VITE_SKIP_REQUEST_ENCRYPTION;
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import type { AxiosResponse, InternalAxiosRequestConfig, Method } from 'axios';
|
import type { AxiosResponse, InternalAxiosRequestConfig, Method } from 'axios';
|
||||||
import { unref } from 'vue';
|
import { unref } from 'vue';
|
||||||
import { API_BASE_URL, LAYOUT_PATH, DATA_SECRET_KEY, REQUEST_ENCRYPTION } from '@/config/setting';
|
import { API_BASE_URL, LAYOUT_PATH, DATA_SECRET_KEY, SKIP_REQUEST_ENCRYPTION } from '@/config/setting';
|
||||||
import type { ApiResult } from '@/api';
|
import type { ApiResult } from '@/api';
|
||||||
import router from '@/router';
|
import router from '@/router';
|
||||||
import { isWhiteList } from '@/router/routes';
|
import { isWhiteList } from '@/router/routes';
|
||||||
@ -64,7 +64,8 @@ export function requestInterceptor(config: SecureRequestConfig) {
|
|||||||
config.url = toURLSearch(config.params, config.url);
|
config.url = toURLSearch(config.params, config.url);
|
||||||
config.params = {};
|
config.params = {};
|
||||||
}
|
}
|
||||||
if (REQUEST_ENCRYPTION) {
|
console.log("是否需要加密->", '1' !== SKIP_REQUEST_ENCRYPTION)
|
||||||
|
if ('1' !== SKIP_REQUEST_ENCRYPTION) {
|
||||||
// 是否加密
|
// 是否加密
|
||||||
const shouldEncrypt = (
|
const shouldEncrypt = (
|
||||||
!config.skipEncryption &&
|
!config.skipEncryption &&
|
||||||
|
|||||||
@ -5,7 +5,9 @@ import Compression from 'vite-plugin-compression';
|
|||||||
import Components from 'unplugin-vue-components/vite';
|
import Components from 'unplugin-vue-components/vite';
|
||||||
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
|
||||||
import { EleAdminResolver } from 'ele-admin-plus/es/utils/resolvers';
|
import { EleAdminResolver } from 'ele-admin-plus/es/utils/resolvers';
|
||||||
import GenSW from 'workbox-webpack-plugin';
|
// 1. 导入 VitePWA 插件
|
||||||
|
import { VitePWA } from 'vite-plugin-pwa'
|
||||||
|
|
||||||
export default defineConfig(({ command }) => {
|
export default defineConfig(({ command }) => {
|
||||||
const isBuild = command === 'build';
|
const isBuild = command === 'build';
|
||||||
const alias = {
|
const alias = {
|
||||||
@ -14,12 +16,49 @@ export default defineConfig(({ command }) => {
|
|||||||
};
|
};
|
||||||
const plugins = [
|
const plugins = [
|
||||||
vue(),
|
vue(),
|
||||||
new GenSW.GenerateSW({
|
VitePWA({
|
||||||
// 配置选项
|
injectRegister: 'auto',
|
||||||
swDest: 'service-worker.js', // Service Worker 的输出文件路径
|
devOptions: {
|
||||||
clientsClaim: true,
|
enabled: process.env.NODE_ENV === 'development', // 开发模式也启用
|
||||||
skipWaiting: true,
|
type: 'module' // 现代浏览器支持
|
||||||
exclude: [/\.map$/, /asset-manifest\.json$/], // 可选:排除某些文件
|
},
|
||||||
|
includeAssets: ['favicon.ico', 'robots.txt'],
|
||||||
|
strategies: 'injectManifest', // 使用自定义SW模式
|
||||||
|
srcDir: 'public',
|
||||||
|
filename: 'sw.js', // 你的自定义SW文件名
|
||||||
|
// 核心配置项
|
||||||
|
registerType: 'autoUpdate', // 更新策略:autoUpdate(自动) 或 prompt(手动)
|
||||||
|
workbox: {
|
||||||
|
cleanupOutdatedCaches: true,
|
||||||
|
maximumFileSizeToCacheInBytes: 10 * 1024 * 1024, // 10MB
|
||||||
|
sourcemap: true,
|
||||||
|
// Workbox 配置
|
||||||
|
globPatterns: ['**/*.{js,css,html,ico,png,svg,webp,woff2}'],
|
||||||
|
skipWaiting: true, // 新SW立即接管控制
|
||||||
|
clientsClaim: true, // 立即控制现有客户端
|
||||||
|
navigateFallback: '/index.html', // SPA 回退路由
|
||||||
|
},
|
||||||
|
// 应用清单配置
|
||||||
|
manifest: {
|
||||||
|
name: '我的应用',
|
||||||
|
short_name: '应用',
|
||||||
|
start_url: '/',
|
||||||
|
display: 'standalone',
|
||||||
|
background_color: '#ffffff',
|
||||||
|
theme_color: '#42b883',
|
||||||
|
icons: [
|
||||||
|
{
|
||||||
|
src: 'icon-192.png',
|
||||||
|
sizes: '192x192',
|
||||||
|
type: 'image/png'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
src: 'icon-512.png',
|
||||||
|
sizes: '512x512',
|
||||||
|
type: 'image/png'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
if (isBuild) {
|
if (isBuild) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user