19yuke2-frontend/vite.config.ts

179 lines
4.7 KiB
TypeScript
Raw Normal View History

2023-02-05 18:11:34 +08:00
import path from 'path'
import { defineConfig } from 'vite'
import Preview from 'vite-plugin-vue-component-preview'
import Vue from '@vitejs/plugin-vue'
import Pages from 'vite-plugin-pages'
import generateSitemap from 'vite-ssg-sitemap'
import Layouts from 'vite-plugin-vue-layouts'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Markdown from 'vite-plugin-vue-markdown'
import { VitePWA } from 'vite-plugin-pwa'
import VueI18n from '@intlify/unplugin-vue-i18n/vite'
import Inspect from 'vite-plugin-inspect'
import Inspector from 'vite-plugin-vue-inspector'
import LinkAttributes from 'markdown-it-link-attributes'
import Unocss from 'unocss/vite'
import Shiki from 'markdown-it-shiki'
import VueMacros from 'unplugin-vue-macros/vite'
2023-02-09 22:41:12 +08:00
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
2023-02-18 14:56:16 +08:00
import vuetify from 'vite-plugin-vuetify'
2023-02-09 22:41:12 +08:00
2023-02-05 18:11:34 +08:00
export default defineConfig({
resolve: {
alias: {
'~/': `${path.resolve(__dirname, 'src')}/`,
},
},
plugins: [
Preview(),
VueMacros({
plugins: {
vue: Vue({
include: [/\.vue$/, /\.md$/],
reactivityTransform: true,
}),
},
}),
// https://github.com/hannoeru/vite-plugin-pages
Pages({
extensions: ['vue', 'md'],
2023-02-18 14:32:31 +08:00
dirs: [
{ dir: 'src/pages', baseRoute: '' },
{ dir: 'src/posts', baseRoute: 'posts' },
],
2023-02-05 18:11:34 +08:00
}),
// https://github.com/JohnCampionJr/vite-plugin-vue-layouts
Layouts(),
// https://github.com/antfu/unplugin-auto-import
AutoImport({
imports: [
'vue',
'vue-router',
'vue-i18n',
'vue/macros',
'@vueuse/head',
'@vueuse/core',
],
dts: 'src/auto-imports.d.ts',
dirs: ['src/composables'],
2023-02-05 18:11:34 +08:00
vueTemplate: true,
2023-02-09 22:41:12 +08:00
resolvers: [ElementPlusResolver()],
2023-02-05 18:11:34 +08:00
}),
// https://github.com/antfu/unplugin-vue-components
Components({
// 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$/],
dts: 'src/components.d.ts',
2023-02-09 22:41:12 +08:00
resolvers: [ElementPlusResolver()],
2023-02-05 18:11:34 +08:00
}),
// https://github.com/antfu/unocss
// see unocss.config.ts for config
Unocss(),
// https://github.com/antfu/vite-plugin-vue-markdown
// Don't need this? Try vitesse-lite: https://github.com/antfu/vitesse-lite
Markdown({
// wrapperClasses: 'prose m-auto text-left',
2023-02-05 18:11:34 +08:00
headEnabled: true,
markdownItSetup(md) {
// https://prismjs.com/
md.use(Shiki, {
theme: {
light: 'vitesse-light',
dark: 'vitesse-dark',
},
})
md.use(LinkAttributes, {
matcher: (link: string) => /^https?:\/\//.test(link),
attrs: {
target: '_blank',
rel: 'noopener',
},
})
},
}),
// https://github.com/antfu/vite-plugin-pwa
VitePWA({
registerType: 'autoUpdate',
includeAssets: ['favicon.svg', 'safari-pinned-tab.svg'],
manifest: {
2023-02-11 11:40:59 +08:00
name: '合肥市南园学校19预科2班',
short_name: '合肥市南园学校19预科2班',
2023-02-05 18:11:34 +08:00
theme_color: '#ffffff',
icons: [
{
src: '/pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: '/pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
},
{
src: '/pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable',
},
],
},
}),
// https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n
VueI18n({
runtimeOnly: true,
compositionOnly: true,
fullInstall: true,
include: [path.resolve(__dirname, 'locales/**')],
}),
// https://github.com/antfu/vite-plugin-inspect
// Visit http://localhost:3333/__inspect/ to see the inspector
Inspect(),
// https://github.com/webfansplz/vite-plugin-vue-inspector
Inspector({
toggleButtonVisibility: 'never',
}),
2023-02-16 22:28:04 +08:00
vuetify({ autoImport: true }),
2023-02-05 18:11:34 +08:00
],
// https://github.com/vitest-dev/vitest
test: {
include: ['test/**/*.test.ts'],
environment: 'jsdom',
deps: {
inline: ['@vue', '@vueuse', 'vue-demi'],
},
},
// https://github.com/antfu/vite-ssg
ssgOptions: {
script: 'async',
formatting: 'minify',
onFinished() {
generateSitemap()
},
2023-02-05 18:11:34 +08:00
},
ssr: {
// TODO: workaround until they support native ESM
2023-02-18 11:25:03 +08:00
noExternal: ['workbox-window', /vue-i18n/, 'vuetify'],
2023-02-05 18:11:34 +08:00
},
})