-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.config.ts
165 lines (160 loc) · 3.98 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { defineConfig } from "vite";
import { VitePWA, VitePWAOptions } from "vite-plugin-pwa";
import react from "@vitejs/plugin-react";
import path from "path";
import { dependencies } from "./package.json";
function renderChunks(deps: Record<string, string>) {
// eslint-disable-next-line prefer-const
let chunks = {};
Object.keys(deps).forEach((key) => {
if (["react", "react-dom"].includes(key)) return;
chunks[key] = [key];
});
return chunks;
}
function pathResolve(dir: string) {
return path.join(__dirname, ".", dir);
}
const buildTarget = process.env.BUILD_TARGET || "web";
const isProduction = process.env.NODE_ENV === "production";
const isWeb = buildTarget === "web";
const isChrome = buildTarget === "chrome";
const manifestForPlugin: Partial<VitePWAOptions> = {
registerType: "prompt",
includeAssets: ["favicon.ico", "apple-touch-icon.png", "masked-icon.svg"],
manifest: {
name: "Paige: your pesonal space",
short_name: "Paige",
description:
"a space where you can customize your focus, immerse yourself in calm scenes, and find inspiration whenever you open a new tab in your browser",
icons: [
{
src: "/pwa-64x64.png",
sizes: "64x64",
type: "image/png",
},
{
src: "/pwa-192x192.png",
sizes: "192x192",
type: "image/png",
},
{
src: "/pwa-512x512.png",
sizes: "512x512",
type: "image/png",
},
{
src: "/maskable-icon-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "any maskable",
},
{
src: "/apple-touch-icon-180x180.png",
sizes: "180x180",
type: "image/png",
purpose: "apple touch icon",
},
],
theme_color: "#171717",
background_color: "#e8ebf2",
display: "standalone",
scope: "/",
start_url: "/",
orientation: "landscape",
},
devOptions: {
enabled: false,
},
workbox: {
globPatterns: ["**/*.{js,css,html,ico,png,svg,tff}"],
runtimeCaching: [
{
urlPattern: ({ request }) => request.destination === "image",
handler: "CacheFirst",
options: {
cacheName: "images-cache",
expiration: {
maxEntries: 10,
},
},
},
],
cleanupOutdatedCaches: false,
sourcemap: true,
},
};
const plugins = isWeb ? [react(), VitePWA(manifestForPlugin)] : [react()];
const manualChunks =
isChrome && !isProduction
? null
: {
vendor: ["react", "react-dom"],
...renderChunks(dependencies),
};
export default defineConfig({
plugins,
resolve: {
alias: [
{
find: "@/",
replacement: pathResolve("src/"),
},
{
find: "stitches.config",
replacement: pathResolve("stitches.config.ts"),
},
{
find: "@utils",
replacement: pathResolve("src/utils"),
},
{
find: "@context",
replacement: pathResolve("src/context"),
},
{
find: "@components",
replacement: pathResolve("src/components"),
},
{
find: "@store",
replacement: pathResolve("src/store"),
},
{
find: "@constants",
replacement: pathResolve("src/constants"),
},
{
find: "@types",
replacement: pathResolve("src/types"),
},
{
find: "@hooks",
replacement: pathResolve("src/hooks"),
},
{
find: "@api",
replacement: pathResolve("src/api"),
},
],
},
build: {
rollupOptions: {
input: {
// the default entry point
index: "./index.html",
// 1️⃣
"service-worker": "./src/service-worker.ts",
},
output: {
chunkFileNames: "assets/[name].min.js",
entryFileNames: (assetInfo) => {
return assetInfo.name === "service-worker"
? "service-worker.js"
: "assets/[name].min.js";
},
manualChunks,
},
},
},
});