-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
104 lines (98 loc) · 2.83 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { ConfigEnv, UserConfig } from "vite";
import reactRefresh from "@vitejs/plugin-react-refresh";
import type { ManifestOptions, VitePWAOptions } from "vite-plugin-pwa";
import { VitePWA } from "vite-plugin-pwa";
import replace from "@rollup/plugin-replace";
import viteCompression from "vite-plugin-compression";
const pwaOptions: Record<string, any> = {
mode: "development",
includeAssets: ["logo.png"],
description: "portfolio website of MahdiPakravan , developed by reactJS .",
start_url: "/",
display: "standalone",
background_color: "#ffffff",
lang: "en",
scope: "/",
theme_color: "#011627",
dir: "ltr",
orientation: "portrait",
display_override: ["standalone"],
related_applications: [],
shortcuts: [
{
name: "MahdiPakravan",
url: "https://mahdipakravan.ir",
description: "Mahdipkarvan shortcut",
},
],
manifest: {
name: "MahdiPakravan website !",
short_name: "mahdipakravan",
theme_color: "#011627",
icons: [
{
src: "icons/android/android-launchericon-512-512.png",
sizes: "512x512",
},
{
src: "icons/android/android-launchericon-192-192.png",
sizes: "192x192",
},
{
src: "icons/android/android-launchericon-144-144.png",
sizes: "144x144",
},
{
src: "icons/android/android-launchericon-96-96.png",
sizes: "96x96",
},
{
src: "icons/android/android-launchericon-72-72.png",
sizes: "72x72",
},
{
src: "icons/android/android-launchericon-48-48.png",
sizes: "48x48",
},
],
},
devOptions: {
enabled: process.env.SW_DEV === "true",
/* when using generateSW the PWA plugin will switch to classic */
type: "module",
navigateFallback: "index.html",
},
};
const replaceOptions = { __DATE__: new Date().toISOString() };
const claims = process.env.CLAIMS === "true";
const reload = process.env.RELOAD_SW === "true";
const selfDestroying = process.env.SW_DESTROY === "true";
if (process.env.SW === "true") {
//Test
pwaOptions.srcDir = "src";
pwaOptions.filename = claims
? "serviceworker/claims-sw.ts"
: "serviceworker/prompt-sw.ts";
pwaOptions.strategies = "injectManifest";
(pwaOptions.manifest as Partial<ManifestOptions>).name =
"MahdiPakravan | Portfolio website";
(pwaOptions.manifest as Partial<ManifestOptions>).short_name =
"MahdiPakravan";
}
if (claims) pwaOptions.registerType = "autoUpdate";
if (reload) {
// @ts-expect-error just ignore
replaceOptions.__RELOAD_SW__ = "true";
}
if (selfDestroying) pwaOptions.selfDestroying = selfDestroying;
export default ({ command, mode }: ConfigEnv): UserConfig => {
return {
base: "/",
plugins: [
reactRefresh(),
VitePWA(pwaOptions),
replace(replaceOptions) as any,
// viteCompression(),
],
};
};