Fork of atp.tools as a universal profile for people on the ATmosphere
at main 1.7 kB view raw
1import path from "path"; 2import { defineConfig } from "vite"; 3import preact from "@preact/preset-vite"; 4import { TanStackRouterVite } from "@tanstack/router-plugin/vite"; 5 6import metadata from "./public/oauth/client-metadata.json" with { type: "json" }; 7 8// https://vite.dev/config/ 9export default defineConfig({ 10 plugins: [ 11 TanStackRouterVite(), 12 preact(), 13 { 14 enforce: "pre", 15 name: "oauth-config", 16 config(_conf, { command }) { 17 if (command === "build") { 18 process.env.VITE_OAUTH_CLIENT_ID = metadata.client_id as string; 19 process.env.VITE_OAUTH_REDIRECT_URI = ( 20 metadata.redirect_uris as string[] 21 )[0]; 22 } else { 23 const SERVER_HOST = "127.0.0.1"; 24 const SERVER_PORT = 5173; 25 26 const redirectUri = (() => { 27 const url = new URL((metadata.redirect_uris as string[])[0]); 28 return `http://${SERVER_HOST}:${SERVER_PORT}${url.pathname}`; 29 })(); 30 31 const clientId = 32 `http://localhost` + 33 `?redirect_uri=${encodeURIComponent(redirectUri)}` + 34 `&scope=${encodeURIComponent(metadata.scope as string)}`; 35 36 process.env.VITE_DEV_SERVER_PORT = "" + SERVER_PORT; 37 process.env.VITE_OAUTH_CLIENT_ID = clientId; 38 process.env.VITE_OAUTH_REDIRECT_URI = redirectUri; 39 } 40 41 process.env.VITE_CLIENT_URI = metadata.client_uri as string; 42 process.env.VITE_OAUTH_SCOPE = metadata.scope as string; 43 }, 44 }, 45 ], 46 resolve: { 47 alias: { 48 "@": path.resolve(__dirname, "./src"), 49 }, 50 }, 51 server: { 52 host: "127.0.0.1", 53 open: true, 54 }, 55});