vite.config.ts (2371B)
1 import { fileURLToPath, URL } from 'node:url'; 2 import { resolve } from 'path'; 3 import { defineConfig } from 'vite'; 4 import { VitePWA } from 'vite-plugin-pwa'; 5 import fs from 'fs'; 6 import markdownit from 'markdown-it' 7 import vue from '@vitejs/plugin-vue'; 8 9 import { description } from './package.json'; 10 11 // Convert changelog from markdown to HTML 12 const changelog_md: string = fs.readFileSync('./CHANGELOG.md', 'utf-8'); 13 const changelog_html: string = markdownit({ 14 typographer: true, // needed to convert '--' to en-dash 15 }).render(changelog_md.slice(changelog_md.indexOf('\n') + 1)) // render without h1 on first line 16 .replace(/\n/g, ' '); // join lines together 17 18 // https://vitejs.dev/config/ 19 export default defineConfig({ 20 build: { 21 rollupOptions: { 22 input: { 23 index: resolve(__dirname, 'index.html'), 24 not_found: resolve(__dirname, '404.html'), 25 }, 26 }, 27 }, 28 plugins: [ 29 vue(), 30 VitePWA({ 31 injectRegister: 'inline', 32 manifest: { 33 name: 'Running Tools', 34 short_name: 'Running Tools', 35 description: description, 36 theme_color: '#ff8000', 37 background_color: '#ff8000', 38 icons: [ 39 { 40 "src": "./img/icons/android-chrome-192x192.png", 41 "sizes": "192x192", 42 "type": "image/png", 43 }, 44 { 45 "src": "./img/icons/android-chrome-512x512.png", 46 "sizes": "512x512", 47 "type": "image/png", 48 }, 49 { 50 "src": "./img/icons/android-chrome-maskable-192x192.png", 51 "sizes": "192x192", 52 "type": "image/png", 53 "purpose": "maskable", 54 }, 55 { 56 "src": "./img/icons/android-chrome-maskable-512x512.png", 57 "sizes": "512x512", 58 "type": "image/png", 59 "purpose": "maskable", 60 }, 61 ], 62 }, 63 }), 64 ], 65 resolve: { 66 alias: { 67 '@': fileURLToPath(new URL('./src', import.meta.url)), 68 }, 69 }, 70 base: process.env.BASE_URL || '/', 71 define: { 72 'import.meta.env.VITE_DESCRIPTION': `"${description}"`, 73 'import.meta.env.VITE_DOMAIN': process.env.DOMAIN ? `"https://${process.env.DOMAIN}"` : '""', 74 '__CHANGELOG_HTML__': JSON.stringify(changelog_html), 75 }, 76 test: { 77 environment: 'jsdom', 78 include: ['tests/unit/**/*.{test,spec}.?(c|m)[jt]s?(x)'], 79 }, 80 });