146 lines
3.7 KiB
TypeScript
146 lines
3.7 KiB
TypeScript
import path from 'path'
|
|
import { defineConfig } from 'vite'
|
|
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 Inspect from 'vite-plugin-inspect'
|
|
import Prism from 'markdown-it-prism'
|
|
import LinkAttributes from 'markdown-it-link-attributes'
|
|
import Unocss from 'unocss/vite'
|
|
|
|
import legacy from '@vitejs/plugin-legacy'
|
|
|
|
Object.assign(process.env, {
|
|
VITE_COMMIT_REF: process.env.CF_PAGES_COMMIT_SHA || '',
|
|
})
|
|
|
|
export default defineConfig({
|
|
resolve: {
|
|
alias: {
|
|
'~/': `${path.resolve(__dirname, 'src')}/`,
|
|
},
|
|
},
|
|
|
|
plugins: [
|
|
legacy({
|
|
targets: ['defaults', 'not IE 11'],
|
|
}),
|
|
|
|
Vue({
|
|
include: [/\.vue$/, /\.md$/],
|
|
reactivityTransform: true,
|
|
}),
|
|
|
|
// https://github.com/hannoeru/vite-plugin-pages
|
|
Pages({
|
|
extensions: ['vue', 'md'],
|
|
}),
|
|
|
|
// https://github.com/JohnCampionJr/vite-plugin-vue-layouts
|
|
Layouts(),
|
|
|
|
// https://github.com/antfu/unplugin-auto-import
|
|
AutoImport({
|
|
imports: [
|
|
'vue',
|
|
'vue-router',
|
|
'vue/macros',
|
|
'@vueuse/head',
|
|
'@vueuse/core',
|
|
],
|
|
dts: 'src/auto-imports.d.ts',
|
|
dirs: [
|
|
'src/composables',
|
|
'src/store',
|
|
],
|
|
vueTemplate: true,
|
|
}),
|
|
|
|
// 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',
|
|
}),
|
|
|
|
// https://github.com/antfu/unocss
|
|
// see unocss.config.ts for config
|
|
Unocss(),
|
|
|
|
// https://github.com/antfu/vite-plugin-vue-markdown
|
|
Markdown({
|
|
wrapperComponent: 'WrapperMd',
|
|
headEnabled: true,
|
|
markdownItSetup(md) {
|
|
// https://prismjs.com/
|
|
md.use(Prism)
|
|
md.use(LinkAttributes, {
|
|
matcher: (link: string) => /^https?:\/\//.test(link),
|
|
attrs: {
|
|
target: '_blank',
|
|
rel: 'noopener',
|
|
},
|
|
})
|
|
},
|
|
}),
|
|
|
|
// // https://github.com/antfu/vite-plugin-pwa
|
|
// VitePWA({
|
|
// // use default prompt
|
|
// // registerType: 'autoUpdate',
|
|
// registerType: 'prompt',
|
|
// includeAssets: ['favicon.svg', 'safari-pinned-tab.svg'],
|
|
// manifest: {
|
|
// name: '今天我们来做菜',
|
|
// short_name: '来做菜',
|
|
// 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/antfu/vite-plugin-inspect
|
|
// Visit http://localhost:3333/__inspect/ to see the inspector
|
|
Inspect(),
|
|
],
|
|
|
|
// https://github.com/antfu/vite-ssg
|
|
ssgOptions: {
|
|
script: 'async',
|
|
formatting: 'minify',
|
|
onFinished() { generateSitemap() },
|
|
},
|
|
|
|
// https://github.com/vitest-dev/vitest
|
|
test: {
|
|
include: ['test/**/*.test.ts'],
|
|
environment: 'jsdom',
|
|
deps: {
|
|
inline: ['@vue', '@vueuse', 'vue-demi'],
|
|
},
|
|
},
|
|
})
|