its-personal/vite.config.ts

100 lines
3.0 KiB
TypeScript

// vite define config
import { defineConfig } from 'vite'
// vite plugin
import UnoCSS from 'unocss/vite'
import { presetTagify, presetIcons } from 'unocss'
import extractorSvelte from '@unocss/extractor-svelte'
import { imagetools } from 'vite-imagetools'
import { sveltekit as SvelteKit } from '@sveltejs/kit/vite'
import { SvelteKitPWA } from '@vite-pwa/sveltekit'
// postcss & tailwindcss
import TailwindCSS from 'tailwindcss'
import tailwindConfig from './tailwind.config'
// @ts-expect-error ts(7016)
import LightningCSS from 'postcss-lightningcss'
//mine
import { sentrySvelteKit } from '@sentry/sveltekit'
import { purgeCss } from 'vite-plugin-tailwind-purgecss'
import { defineConfig } from 'vitest/config'
import { threeMinifier } from '@yushijinhun/three-minifier-rollup'
import path from 'path'
export default defineConfig({
server: {
host: 'localhost',
port: 5173
},
envPrefix: 'PUBLIC_',
build: {
sourcemap: false,
rollupOptions: {
cache: false
},
// to resolve https://github.com/vitejs/vite/issues/6985
target: 'esnext'
},
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
},
define: {
'process.env.VITE_BUILD_TIME': JSON.stringify(new Date().toISOString())
},
css: {
postcss: {
plugins: [TailwindCSS(tailwindConfig), LightningCSS()]
}
},
ssr: {
noExternal: ['three']
},
resolve: {
alias: {
$lib: path.resolve(__dirname, 'src', 'lib'),
$root: path.resolve(__dirname),
$src: path.resolve(__dirname, 'src'),
$routes: path.resolve(__dirname, 'src', 'routes')
}
},
plugins: [
sentrySvelteKit({
autoUploadSourceMaps: false
// sourceMapsUploadOptions: {
// org: 'mattmor',
// project: 'itspersonal',
// authToken: process.env.SENTRY_AUTH_TOKEN
// },
// telemetry: false
}),
SvelteKit(),
purgeCss({
safelist: {
// any selectors that begin with "hljs-" will not be purged
greedy: [/^hljs-/]
}
}),
{ ...threeMinifier(), enforce: 'pre' },
UnoCSS({
content: { pipeline: { include: [/\.svelte$/, /\.md?$/, /\.ts$/] } },
extractors: [extractorSvelte],
presets: [
presetTagify({
extraProperties: (matched: string) => (matched.startsWith('i-') ? { display: 'inline-block' } : {})
}),
presetIcons({ scale: 1.5 })
]
}),
imagetools(),
SvelteKitPWA({
registerType: 'autoUpdate',
manifest: false,
scope: '/',
workbox: {
globPatterns: ['robots.txt', 'posts.json', '**/*.{js,css,html,svg,ico,png,webp,avif}', 'prerendered/**/*.html'],
globIgnores: ['**/sw*', '**/workbox-*', '*.xml', 'feed.json', 'tags.json']
}
})
]
})