Skip to content

Commit

Permalink
Merge pull request #1298 from geichelberger/vite-variables
Browse files Browse the repository at this point in the history
Replace REACT_ environment variables
  • Loading branch information
Arnei authored Apr 3, 2024
2 parents 68d547d + ce9e402 commit 0e7bffd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Build integrated version
rm -rf build/
export PUBLIC_URL=/editor-ui
export REACT_APP_SETTINGS_PATH="/ui/config/editor/editor-settings.toml"
export VITE_APP_SETTINGS_PATH="/ui/config/editor/editor-settings.toml"
npm run build

FILENAME="oc-editor-$(date --utc +%F).tar.gz"
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="git-commit" content="%REACT_APP_GIT_SHA%">
<meta name="build-date" content="%REACT_APP_BUILD_DATE%">
<meta name="git-commit" content="%VITE_GIT_COMMIT_HASH%">
<meta name="build-date" content="%VITE_APP_BUILD_DATE%">
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ const loadContextSettings = async () => {
basepath += "/";
}

// Construct path to settings file. If the `REACT_APP_SETTINGS_PATH` is
// Construct path to settings file. If the `VITE_APP_SETTINGS_PATH` is
// given and starts with "/", it is interpreted as absolute path from the
// server root.
const settingsPath = import.meta.env.REACT_APP_SETTINGS_PATH || CONTEXT_SETTINGS_FILE;
const settingsPath = import.meta.env.VITE_APP_SETTINGS_PATH || CONTEXT_SETTINGS_FILE;
const base = settingsPath.startsWith("/") ? "" : basepath;
const url = `${window.location.origin}${base}${settingsPath}`;
let response;
Expand Down
5 changes: 5 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import svgr from "vite-plugin-svgr";
import eslint from "vite-plugin-eslint";
import child from "child_process";

const commitHash = child.execSync("git rev-parse HEAD").toString().trim();

// https://vitejs.dev/config/
export default defineConfig(() => {
Expand All @@ -26,6 +29,8 @@ export default defineConfig(() => {
// Workaround, see https://github.com/vitejs/vite/discussions/5912#discussioncomment-6115736
define: {
global: "globalThis",
'import.meta.env.VITE_GIT_COMMIT_HASH': JSON.stringify(commitHash),
'import.meta.env.VITE_APP_BUILD_DATE': JSON.stringify(new Date().toISOString()),
},
test: {
globals: true,
Expand Down

0 comments on commit 0e7bffd

Please sign in to comment.