diff --git a/.env b/.env index 619fce7..ec888d4 100644 --- a/.env +++ b/.env @@ -1,3 +1,5 @@ +VITE_BASE_PATH=/quiz + VITE_SUPABASE_URL=https://.supabase.co VITE_SUPABASE_ANON_KEY= diff --git a/src/config/assets.ts b/src/config/assets.ts new file mode 100644 index 0000000..b2d355f --- /dev/null +++ b/src/config/assets.ts @@ -0,0 +1,7 @@ +export function base (): string { + return import.meta.env.VITE_BASE_PATH || '/' +} + +export function image (path: string): string { + return (base() + '/assets/images/' + path).replace(/([^:]\/)\/+/g, '$1') +} diff --git a/src/main.tsx b/src/main.tsx index 74b5355..281dc99 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -5,11 +5,13 @@ import { BrowserRouter } from 'react-router-dom' import './config/i18n' import App from './App.tsx' import './index.css' +import { base } from './config/assets.ts' -ReactDOM.createRoot(document.getElementById('root')!).render( - - - - - , -) +ReactDOM.createRoot(document.getElementById('root')!) + .render( + + + + + , + ) diff --git a/src/view/components/game/GameCorrectAnswer.tsx b/src/view/components/game/GameCorrectAnswer.tsx index 6e6f33b..24902a0 100644 --- a/src/view/components/game/GameCorrectAnswer.tsx +++ b/src/view/components/game/GameCorrectAnswer.tsx @@ -1,4 +1,5 @@ import { GameQuestionComponentsProps } from './GameQuestion.tsx' +import { image } from '../../../config/assets.ts' export function GameCorrectAnswer ({ finishQuestion }: GameQuestionComponentsProps) { return ( @@ -6,7 +7,7 @@ export function GameCorrectAnswer ({ finishQuestion }: GameQuestionComponentsPro PHPinga

Certa a resposta!

diff --git a/src/view/components/game/GameTimeExpired.tsx b/src/view/components/game/GameTimeExpired.tsx index 4ae699a..2fb77dd 100644 --- a/src/view/components/game/GameTimeExpired.tsx +++ b/src/view/components/game/GameTimeExpired.tsx @@ -1,4 +1,5 @@ import { GameQuestionComponentsProps } from './GameQuestion.tsx' +import { image } from '../../../config/assets.ts' export function GameTimeExpired ({ finishQuestion }: GameQuestionComponentsProps) { return ( @@ -6,7 +7,7 @@ export function GameTimeExpired ({ finishQuestion }: GameQuestionComponentsProps PHPinga

Acabou o tempo!

diff --git a/src/view/components/game/GameWrongAnswer.tsx b/src/view/components/game/GameWrongAnswer.tsx index f4a9da8..446dafb 100644 --- a/src/view/components/game/GameWrongAnswer.tsx +++ b/src/view/components/game/GameWrongAnswer.tsx @@ -1,4 +1,5 @@ import { GameQuestionComponentsProps } from './GameQuestion.tsx' +import { image } from '../../../config/assets.ts' export function GameWrongAnswer ({ finishQuestion }: GameQuestionComponentsProps) { return ( @@ -6,7 +7,7 @@ export function GameWrongAnswer ({ finishQuestion }: GameQuestionComponentsProps PHPinga

Bebe!

diff --git a/src/view/pages/game/GameEndPage.tsx b/src/view/pages/game/GameEndPage.tsx index a55356f..c66193a 100644 --- a/src/view/pages/game/GameEndPage.tsx +++ b/src/view/pages/game/GameEndPage.tsx @@ -1,5 +1,6 @@ import { useNavigate, useParams } from 'react-router-dom' import { useTranslation } from 'react-i18next' +import { image } from '../../../config/assets.ts' export function GameEndPage () { const params = useParams() @@ -16,7 +17,7 @@ export function GameEndPage () { PHPinga

{t('title')}

diff --git a/vite.config.ts b/vite.config.ts index 4ac6df7..2775f05 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,8 +1,12 @@ -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import react from '@vitejs/plugin-react' // https://vitejs.dev/config/ -export default defineConfig({ - plugins: [react()], - base: '/quiz', -}) +export default ({ mode }: { mode: string}) => { + process.env = {...process.env, ...loadEnv(mode, process.cwd())} + + return defineConfig({ + plugins: [react()], + base: process.env.VITE_BASE_PATH || '/', + }) +}