Skip to content

Commit

Permalink
Use an env for loading assets (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanWebb authored Feb 2, 2024
1 parent d8322fc commit 9e53178
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Uses Vite's method of setting environment variables
# https://vitejs.dev/guide/env-and-mode

# The public path for asset loading, this needs to be a publically accessible URL on the
# production version
VITE_PUBLIC_PATH=/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ node_modules

# dotenv environment variables file
.env
!.env.example

# Build output
dist
Expand Down
4 changes: 3 additions & 1 deletion src/components/Logo/Logo.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import register from 'preact-custom-element';

import config from '../../config';

export default function Logo() {
return (
<img
src="/recycling-locator-logo.webp"
src={`${config.publicPath}recycling-locator-logo.webp`}
alt="Recycling Locator"
width="230"
height="42"
Expand Down
5 changes: 5 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const config = {
publicPath: import.meta.env.VITE_PUBLIC_PATH ?? '/',
};

export default config;

0 comments on commit 9e53178

Please sign in to comment.