-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
261 lines (239 loc) · 6.7 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
import { resolve } from 'node:path'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import i18n from '@intlify/unplugin-vue-i18n/vite'
import unhead from '@unhead/addons/vite'
import { SchemaOrgResolver, schemaAutoImports } from '@unhead/schema-org/vue'
import { unheadVueComposablesImports } from '@unhead/vue'
import sitemap from 'vite-ssg-sitemap'
import windicss from 'vite-plugin-windicss'
import autoImport from 'unplugin-auto-import/vite'
import components from 'unplugin-vue-components/vite'
import markdown from 'unplugin-vue-markdown/vite'
import { VitePWA as pwa } from 'vite-plugin-pwa'
import { VueRouterAutoImports } from 'unplugin-vue-router'
import router from 'unplugin-vue-router/vite'
import layouts from 'vite-plugin-vue-layouts'
import mdAnchor from 'markdown-it-anchor'
import mdLinkAttr from 'markdown-it-link-attributes'
import mdPrism from 'markdown-it-prism'
/**
* @see https://vitejs.dev/config/
*/
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, '.', ['BASE', 'FIREBASE', 'VITE'])
const FIREBASE_CONFIG = {
projetId: env.VITE_PROJECT_ID,
appId: env.FIREBASE_APP_ID,
apiKey: env.FIREBASE_API_KEY,
messagingSenderId: env.FIREBASE_MESSAGING_SENDER_ID,
measurementId: env.FIREBASE_MEASUREMENT_ID,
storageBucket: `${env.VITE_PROJECT_ID}.appspot.com`,
authDomain: `${env.VITE_PROJECT_ID}.firebaseapp.com`,
}
// const routeMeta: Record<string, any> = {
// locale: 'id',
// layout: 'default',
// }
return {
resolve: {
alias: {
'~/': `${resolve(__dirname, 'src')}/`,
},
},
// optimizeDeps: {
// include: [
// '@vueuse/core',
// '@vueuse/head',
// 'vue-i18n',
// 'vue-router',
// 'vue',
// ],
// exclude: [
// 'vue-demi',
// ],
// },
define: {
'FIREBASE_CONFIG': JSON.stringify(FIREBASE_CONFIG),
'import.meta.env.BASE_URL': JSON.stringify(
command === 'serve' ? '/' : env.BASE_URL,
),
},
/**
* @see https://github.com/antfu/vite-ssg
*/
ssgOptions: {
script: 'async',
formatting: 'minify',
onFinished() {
/**
* @see https://github.com/jbaubree/vite-ssg-sitemap
*/
sitemap({
hostname: env.BASE_URL || 'http://localhost',
exclude: ['/index', '/404'],
robots: [
{ userAgent: '*', disallow: ['/assets', '/images', '/CNAME', '/.nojekyll'] },
{ userAgent: 'Googlebot-Image', disallow: '/' },
],
})
},
},
/**
* @see https://github.com/vitest-dev/vitest
*/
test: {
include: ['test/**/*.test.ts'],
environment: 'happy-dom',
globals: true,
deps: {
inline: ['@vue', '@vueuse', 'vue-demi'],
},
},
ssr: {
/**
* TODO: workaround until they support native ESM
* @link https://github.com/antfu/vite-ssg/issues/286#issuecomment-1285885878
*/
noExternal: [/vue-i18n/],
},
plugins: [
vue({
include: [/\.vue$/, /\.md$/],
}),
/**
* @see https://github.com/antfu/unplugin-auto-import
*/
autoImport({
dts: 'src/auto-imports.d.ts',
dirs: [
'src/composables',
'src/store',
],
imports: [
'@vueuse/core',
'vue-i18n',
unheadVueComposablesImports,
VueRouterAutoImports,
{
'@unhead/schema-org': schemaAutoImports,
},
{
// add any other imports you were relying on
'vue-router/auto': ['useLink'],
},
'vue/macros',
'vue',
],
vueTemplate: true,
}),
/**
* @see https://github.com/antfu/unplugin-vue-components
*/
components({
dts: 'src/components.d.ts',
directoryAsNamespace: true,
// allow auto load markdown components under `./src/components/`
extensions: ['vue', 'md'],
// allow auto import and register components used in markdown
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
resolvers: [
SchemaOrgResolver(),
],
}),
/**
* @see https://github.com/JohnCampionJr/vite-plugin-vue-layouts
*/
layouts(),
/**
* @see https://unhead.unjs.io
*/
unhead(),
/**
* @see https://github.com/posva/unplugin-vue-router
*/
router({
dts: 'src/typed-router.d.ts',
extensions: ['.vue', '.md'],
}),
/**
* @see https://github.com/antfu/vite-plugin-windicss
*/
windicss({
safelist: 'prose prose-sm m-auto text-left',
preflight: {
enableAll: true,
},
}),
/**
* @see https://github.com/unplugin/unplugin-vue-markdown
*/
markdown({
wrapperComponent: 'site-content',
wrapperClasses: 'prose max-w-none',
headEnabled: true,
excerpt: true,
/**
* @see https://markdown-it.github.io/markdown-it/
*/
markdownItOptions: {
html: true,
typographer: true,
},
markdownItSetup(md) {
md.use(mdPrism)
md.use(mdAnchor, {
permalink: mdAnchor.permalink.ariaHidden({
renderAttrs: () => ({ 'aria-hidden': 'true' }),
}),
})
md.use(mdLinkAttr, {
matcher: (link: string) => /^(https?:\/\/|\/\/)/.test(link),
attrs: {
target: '_blank',
rel: 'noopener',
},
})
},
}),
/**
* @see https://github.com/antfu/vite-plugin-pwa
*/
pwa({
registerType: 'autoUpdate',
includeAssets: ['favicon.ico', 'assets/favicon.svg', 'assets/safari-pinned-tab.svg'],
manifest: {
name: 'Creasi.CO',
short_name: 'Creasi.CO',
theme_color: '#ffffff',
icons: [
{
src: '/assets/icon-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: '/assets/icon-512x512.png',
sizes: '512x512',
type: 'image/png',
},
{
src: '/assets/icon-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable',
},
],
},
}),
/**
* @see https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n
*/
i18n({
runtimeOnly: true,
compositionOnly: true,
include: [resolve(__dirname, 'locales/**')],
}),
],
}
})