Skip to content

Commit

Permalink
fix(vite): fix env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
prix0007 committed Sep 29, 2023
1 parent a61165d commit e1b3a69
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
8 changes: 4 additions & 4 deletions plugin/.env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
REACT_APP_API_URL=https://cairo-compile-remix-test.nethermind.io
REACT_APP_DEVNET_URL=http://127.0.0.1:5050
REACT_APP_REMOTE_DEVNET_URL=https://starknet-devnet-dev.nethermind.io
REACT_APP_VERSION=$npm_package_version
VITE_API_URL=https://cairo-compile-remix-test.nethermind.io
VITE_DEVNET_URL=http://127.0.0.1:5050
VITE_REMOTE_DEVNET_URL=https://starknet-devnet-dev.nethermind.io
VITE_VERSION=$npm_package_version
14 changes: 14 additions & 0 deletions plugin/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_URL: string
readonly VITE_API_URL: string
readonly VITE_DEVNET_URL: string
readonly VITE_REMOTE_DEVNET_URL: string
readonly VITE_VERSION: string
// more env variables...
}

interface ImportMeta {
readonly env: ImportMetaEnv
}
2 changes: 1 addition & 1 deletion plugin/src/features/CairoVersion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const CairoVersion: React.FC = () => {
const [versions] = useState<string[]>([
'cairo-compile 2.2.0'
])
const pluginVersion = process.env.VITE_VERSION !== undefined ? `v${process.env.VITE_VERSION}` : 'v0.2.0'
const pluginVersion = import.meta.env.VITE_VERSION !== undefined ? `v${import.meta.env.VITE_VERSION}` : 'v0.2.0'

useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
Expand Down
1 change: 0 additions & 1 deletion plugin/src/react-app-env.d.ts

This file was deleted.

6 changes: 3 additions & 3 deletions plugin/src/utils/network.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type DevnetAccount } from '../types/accounts'

const apiUrl = process.env.VITE_API_URL ?? 'cairo-compile-remix-test.nethermind.io'
const devnetUrl = process.env.VITE_DEVNET_URL ?? 'http://localhost:5050'
const remoteDevnetUrl = process.env.VITE_REMOTE_DEVNET_URL ?? 'https://starknet-devnet-dev.nethermind.io'
const apiUrl = import.meta.env.VITE_API_URL ?? 'cairo-compile-remix-test.nethermind.io'
const devnetUrl = import.meta.env.VITE_DEVNET_URL ?? 'http://localhost:5050'
const remoteDevnetUrl = import.meta.env.VITE_REMOTE_DEVNET_URL ?? 'https://starknet-devnet-dev.nethermind.io'

interface Devnet {
name: string
Expand Down
4 changes: 4 additions & 0 deletions plugin/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export default defineConfig(() => {
define: {
'process.env': {}
},
server: {
port: 3000,
hmr: true
},
build: {
outDir: 'build'
},
Expand Down

0 comments on commit e1b3a69

Please sign in to comment.