mirror of
https://github.com/vitest-dev/vitest.git
synced 2025-12-08 18:26:03 +00:00
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import fs from 'fs'
|
|
import type { Plugin } from 'vite'
|
|
import { defineConfig } from 'vite'
|
|
import Components from 'unplugin-vue-components/vite'
|
|
import Unocss from 'unocss/vite'
|
|
import { presetAttributify, presetIcons, presetUno } from 'unocss'
|
|
import { resolve } from 'pathe'
|
|
|
|
export default defineConfig({
|
|
plugins: [
|
|
Components({
|
|
include: [/\.vue/, /\.md/],
|
|
dts: true,
|
|
}),
|
|
Unocss({
|
|
shortcuts: [
|
|
['btn', 'px-4 py-1 rounded inline-flex justify-center gap-2 text-white leading-30px children:mya !no-underline cursor-pointer disabled:cursor-default disabled:bg-gray-600 disabled:opacity-50'],
|
|
],
|
|
presets: [
|
|
presetUno({
|
|
dark: 'media',
|
|
}),
|
|
presetAttributify(),
|
|
presetIcons({
|
|
scale: 1.2,
|
|
}),
|
|
],
|
|
}),
|
|
IncludesPlugin(),
|
|
],
|
|
|
|
optimizeDeps: {
|
|
include: [
|
|
'vue',
|
|
'@vueuse/core',
|
|
],
|
|
exclude: [
|
|
'vue-demi',
|
|
],
|
|
},
|
|
})
|
|
|
|
function IncludesPlugin(): Plugin {
|
|
return {
|
|
name: 'include-plugin',
|
|
enforce: 'pre',
|
|
transform(code, id) {
|
|
let changed = false
|
|
code = code.replace(/\[@@include\]\((.*?)\)/, (_, url) => {
|
|
changed = true
|
|
const full = resolve(id, url)
|
|
return fs.readFileSync(full, 'utf-8')
|
|
})
|
|
if (changed)
|
|
return code
|
|
},
|
|
}
|
|
}
|