-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathvite.config.mjs
More file actions
160 lines (152 loc) · 4.6 KB
/
vite.config.mjs
File metadata and controls
160 lines (152 loc) · 4.6 KB
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
import path from 'node:path'
import vue from '@vitejs/plugin-vue'
import { VitePWA } from 'vite-plugin-pwa'
import { imagetools } from 'vite-imagetools'
import { generatedAssetsPlugin } from './build/vite-plugin-generated-assets.mjs'
function normalizeBase(publicUrl) {
if (!publicUrl) return '/'
try {
const u = new URL(publicUrl)
return u.pathname.endsWith('/') ? u.pathname : `${u.pathname}/`
} catch {
// allow plain paths like "/roshar/"
return publicUrl.endsWith('/') ? publicUrl : `${publicUrl}/`
}
}
export default ({ mode }) => {
const isDevBuild = mode === 'dev'
const outDir = isDevBuild ? 'dist/dev' : 'dist/release'
// Keep Vue CLI-style env names (VUE_APP_*) + MAP_DEBUG.
const envPrefix = ['VUE_APP_', 'MAP_']
const base = normalizeBase(process.env.VUE_APP_PUBLIC_URL || '/')
return {
base,
envPrefix,
css: {
preprocessorOptions: {
scss: {
additionalData: '@use "sass:color";\n',
},
},
},
plugins: [
generatedAssetsPlugin(),
imagetools({
include: '**/entries/**/*',
cache: {
enabled: true,
dir: './node_modules/.cache/imagetools',
},
extendTransforms: (builtins) => {
return [
function minWidth (config, ctx) {
const min = Number.parseInt(config.minWidth)
return async function enforceMinWidth (image) {
const metadata = await image.metadata()
if (metadata.width < min) {
ctx.logger.error(`Image must be at least ${min}px wide`)
}
return image
}
},
...builtins
]
},
defaultDirectives: () => {
return new URLSearchParams({
format: 'webp',
minWidth: '500'
})
}
}),
vue(),
!isDevBuild &&
VitePWA({
filename: 'service-worker.js',
registerType: 'autoUpdate',
includeAssets: [
'favicon.ico',
'browserconfig.xml',
'robots.txt',
'img/icons/*',
'img/opengraph.*',
],
manifest: {
name: 'Interactive Map & Timeline of Roshar',
short_name: 'Roshar Map',
theme_color: '#0f3562',
background_color: '#0f3562',
icons: [
{ src: 'img/icons/android-chrome-192x192.png', sizes: '192x192', type: 'image/png' },
{ src: 'img/icons/android-chrome-512x512.png', sizes: '512x512', type: 'image/png' },
{
src: 'img/icons/android-chrome-maskable-192x192.png',
sizes: '192x192',
type: 'image/png',
purpose: 'maskable',
},
{
src: 'img/icons/android-chrome-maskable-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable',
},
],
},
workbox: {
skipWaiting: true,
clientsClaim: true,
maximumFileSizeToCacheInBytes: 10 * 1024 * 1024,
runtimeCaching: [
{
urlPattern: ({ request }) => request.mode === 'navigate',
handler: 'NetworkFirst',
},
{
urlPattern: ({ request, url }) =>
request.destination === 'image' || /\.(?:webp|png|jpe?g|dds)$/.test(url.pathname),
handler: 'CacheFirst',
},
{
urlPattern: ({ url }) => /\/assets\/.*lang-.*\.js$/.test(url.pathname),
handler: 'CacheFirst',
},
],
},
}),
].filter(Boolean),
resolve: {
alias: {
'@': path.resolve(process.cwd(), 'src'),
'@generated': path.resolve(process.cwd(), 'build', 'generated'),
},
extensions: ['.mjs', '.js', '.json', '.vue'],
dedupe: ['vue'],
// Ensure vue can be resolved for the plugin
preserveSymlinks: false,
},
optimizeDeps: {
include: ['vue'],
},
server: {
port: 10010,
},
build: {
outDir,
emptyOutDir: true,
sourcemap: false,
target: 'es2018',
// Limit the size of chunks to 4MB to avoid warnings (language files, esp tr.lang.json is a chunky boy)
chunkSizeWarningLimit: 4000,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return 'vendor'
}
},
},
},
},
}
}