wip: support vite

This commit is contained in:
vben
2021-01-09 23:28:52 +08:00
parent 1d3007f030
commit 99ac309fa9
105 changed files with 954 additions and 2170 deletions

View File

@@ -1,35 +1,31 @@
import { VitePWA } from 'vite-plugin-pwa';
import type { Plugin } from 'vite';
import { ViteEnv } from '../../utils';
export function setupPwaPlugin(
plugins: Plugin[],
env: ViteEnv,
// @ts-ignore
mode: 'development' | 'production'
) {
const { VITE_USE_PWA } = env;
export function configPwaConfig(env: ViteEnv, isBulid: boolean) {
const { VITE_USE_PWA, VITE_GLOB_APP_TITLE, VITE_GLOB_APP_SHORT_NAME } = env;
const pwaPlugin = VitePWA({
manifest: {
name: 'Vben Admin',
short_name: 'vben_admin',
icons: [
{
src: './resource/img/pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: './resource/img/pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
},
],
},
});
if (VITE_USE_PWA) {
plugins.push(pwaPlugin);
if (VITE_USE_PWA && isBulid) {
// vite-plugin-pwa
const pwaPlugin = VitePWA({
manifest: {
name: VITE_GLOB_APP_TITLE,
short_name: VITE_GLOB_APP_SHORT_NAME,
icons: [
{
src: './resource/img/pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: './resource/img/pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
},
],
},
});
return pwaPlugin;
}
return plugins;
return [];
}