| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 1 | import { dirname, resolve } from "node:path"; |
| 2 | import { fileURLToPath } from "node:url"; |
| 3 | import { hmrPlugin, presets } from "vite-plugin-web-components-hmr"; |
| 4 | import { defineConfig } from "vite"; |
| 5 | |
| 6 | const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 7 | |
| 8 | export default defineConfig({ |
| 9 | plugins: [ |
| 10 | hmrPlugin({ |
| 11 | include: ["./src/**/*.ts"], |
| 12 | presets: [presets.lit], |
| 13 | }), |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 14 | // Custom plugin for handling the root path redirect |
| 15 | { |
| 16 | name: "configure-server", |
| 17 | configureServer(server) { |
| 18 | server.middlewares.use((req, res, next) => { |
| 19 | if (req.url === "/") { |
| 20 | res.writeHead(302, { |
| 21 | Location: "/src/web-components/demo/index.html", |
| 22 | }); |
| 23 | res.end(); |
| 24 | return; |
| 25 | } |
| 26 | next(); |
| 27 | }); |
| 28 | }, |
| 29 | }, |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 30 | ], |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 31 | server: { |
| 32 | // Define a middleware to handle the root path redirects |
| 33 | middlewareMode: false, |
| 34 | fs: { |
| 35 | // Allow serving files from these directories |
| Pokey Rule | c575fd7 | 2025-05-06 15:46:38 +0100 | [diff] [blame] | 36 | allow: ["."], |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 37 | }, |
| 38 | }, |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 39 | }); |