-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvite.config.ts
221 lines (203 loc) · 5.67 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import { resolve } from 'node:path'
import { sentryVitePlugin } from '@sentry/vite-plugin'
import i18n from '@intlify/unplugin-vue-i18n/vite'
import vue from '@vitejs/plugin-vue'
import laravel from 'laravel-vite-plugin'
import autoImport from 'unplugin-auto-import/vite'
import components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import windicss from 'vite-plugin-windicss'
import { VitePWA as pwa } from 'vite-plugin-pwa'
import { defineConfig, loadEnv } from 'vite'
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, '.', ['APP', 'FIREBASE', 'SENTRY', 'VITE'])
const rootDir = 'resources/client'
const appURL = new URL(env.APP_URL)
const isDev = ['local', 'testing'].includes(env.APP_ENV)
const firebaseConfig = {
projectId: env.FIREBASE_PROJECT_ID,
appId: env.FIREBASE_APP_ID,
apiKey: env.FIREBASE_API_KEY,
authDomain: `${env.FIREBASE_PROJECT_ID}.firebaseapp.com`,
databaseURL: env.FIREBASE_DATABASE_URL,
storageBucket: `${env.FIREBASE_PROJECT_ID}.appspot.com`,
messagingSenderId: env.FIREBASE_MESSAGING_SENDER_ID,
}
/**
* Define the icons that:
* 1. We want to include in the webmanifest, and
* 2. We want to service worker to pre-cache for offline use.
*/
const manifestIcons = [
{
src: '/vendor/creasico/favicon.svg',
sizes: '512x512',
type: 'image/svg+xml',
},
{
src: '/vendor/creasico/icon-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: '/vendor/creasico/icon-512x512.png',
sizes: '512x512',
type: 'image/png',
},
{
src: '/vendor/creasico/icon-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable',
},
]
return {
resolve: {
alias: {
'~': resolve(__dirname, rootDir),
},
},
optimizeDeps: {
include: [],
exclude: [
'vue-demi',
],
},
build: {
sourcemap: isDev || 'SENTRY_AUTH_TOKEN' in env,
reportCompressedSize: false,
chunkSizeWarningLimit: 2000,
rollupOptions: {
output: {
/**
* @see https://rollupjs.org/configuration-options/#output-manualchunks
*/
manualChunks: (id) => {
if (id.includes('node_modules'))
return 'vendor'
},
},
},
},
define: {
'FIREBASE_CONFIG': JSON.stringify(firebaseConfig),
'import.meta.env.APP_NAME': JSON.stringify(env.APP_NAME),
'import.meta.env.APP_LOCALE': JSON.stringify(env.APP_LOCALE),
'import.meta.env.APP_URL': JSON.stringify(env.APP_URL),
'import.meta.env.APP_ENV': JSON.stringify(env.APP_ENV),
'import.meta.env.FIREBASE_VAPID_KEY': JSON.stringify(env.FIREBASE_VAPID_KEY),
'import.meta.env.SENTRY_DSN': JSON.stringify(env.SENTRY_DSN),
'import.meta.env.SENTRY_PROFILING_ENABLE': Boolean(env.SENTRY_PROFILING_ENABLE ?? 0),
},
server: {
host: appURL.host,
hmr: { host: appURL.host },
https: httpsCert(appURL),
},
plugins: [
vue(),
/**
* @see https://laravel.com/docs/vite
*/
laravel({
input: [
`${rootDir}/app.ts`,
],
// valetTls: env.APP_ENV === 'local' && env.APP_URL.startsWith('https://'),
// refresh: true,
}),
/**
* @see https://www.npmjs.com/package/@sentry/vite-plugin
*/
sentryVitePlugin({
disable: !('SENTRY_AUTH_TOKEN' in env),
org: env.SENTRY_ORG,
project: env.SENTRY_PROJECT,
authToken: env.SENTRY_AUTH_TOKEN,
telemetry: !isDev,
}),
/**
* @see https://windicss.org/integrations/vite.html
*/
windicss(),
/**
* @see https://github.com/antfu/unplugin-auto-import
*/
autoImport({
dts: `${rootDir}/auto-imports.d.ts`,
dirs: [
`${rootDir}/utils`,
// `${rootdir}/store`,
],
imports: [
'@vueuse/core',
{ 'naive-ui': [] },
'vue-i18n',
'vue/macros',
'vue',
],
vueTemplate: true,
}),
/**
* @see https://github.com/antfu/unplugin-vue-components
*/
components({
dts: `${rootDir}/components.d.ts`,
dirs: [
`${rootDir}/components`,
// `${rootdir}/layouts`,
],
directoryAsNamespace: true,
include: [/\.vue$/, /\.vue\?vue/],
resolvers: [
NaiveUiResolver(),
],
}),
/**
* @see https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n
*/
i18n({
runtimeOnly: true,
compositionOnly: true,
include: [resolve(__dirname, './resources/lang/**')],
}),
/**
* @see https://vite-pwa-org.netlify.app/guide
*/
pwa({
scope: '/',
buildBase: '/build/',
devOptions: {
// enabled: (mode !== 'production' && !!env.APP_DEBUG),
},
srcDir: rootDir,
filename: 'sw.ts',
includeAssets: [],
strategies: 'injectManifest',
manifest: {
id: '/',
scope: '/',
start_url: '/',
name: env.APP_NAME,
short_name: env.APP_NAME,
lang: env.APP_LOCALE || 'id',
orientation: 'portrait-primary',
icons: manifestIcons,
},
}),
],
}
})
function httpsCert(url: URL) {
if (url.protocol !== 'https:')
return undefined
try {
return {
cert: resolve(__dirname, 'storage/local-cert.pem'),
key: resolve(__dirname, 'storage/local-key.pem'),
}
}
catch {
return undefined
}
}