From 496dee6e42d32e61e365bceb7f78267106802858 Mon Sep 17 00:00:00 2001 From: Amir Zarrinkafsh Date: Fri, 17 Mar 2023 16:50:27 +1100 Subject: [PATCH] refactor(web): native vite env replacement (#5078) --- .../authelia/docker-compose.frontend.dev.yml | 2 +- web/.env.production | 8 ++++---- web/index.html | 6 +++--- web/vite.config.ts | 16 ++-------------- 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/internal/suites/example/compose/authelia/docker-compose.frontend.dev.yml b/internal/suites/example/compose/authelia/docker-compose.frontend.dev.yml index 98a7d3829..a283a434f 100644 --- a/internal/suites/example/compose/authelia/docker-compose.frontend.dev.yml +++ b/internal/suites/example/compose/authelia/docker-compose.frontend.dev.yml @@ -24,7 +24,7 @@ services: - 'traefik.http.routers.authelia_frontend.entrypoints=https' - 'traefik.http.routers.authelia_frontend.tls=true' environment: - - VITE_PUBLIC_URL=${PathPrefix} + - VITE_BASEPATH=${PathPrefix} networks: - authelianet ... diff --git a/web/.env.production b/web/.env.production index 8a98edcac..e8b1e29ee 100644 --- a/web/.env.production +++ b/web/.env.production @@ -1,9 +1,9 @@ -VITE_LOGO_OVERRIDE={{ .LogoOverride }} -VITE_PUBLIC_URL={{ .Base }} +VITE_BASEPATH={{ .Base }} VITE_DUO_SELF_ENROLLMENT={{ .DuoSelfEnrollment }} +VITE_LOGO_OVERRIDE={{ .LogoOverride }} +VITE_PRIVACY_POLICY_ACCEPT={{ .PrivacyPolicyAccept }} +VITE_PRIVACY_POLICY_URL={{ .PrivacyPolicyURL }} VITE_REMEMBER_ME={{ .RememberMe }} VITE_RESET_PASSWORD={{ .ResetPassword }} VITE_RESET_PASSWORD_CUSTOM_URL={{ .ResetPasswordCustomURL }} -VITE_PRIVACY_POLICY_URL={{ .PrivacyPolicyURL }} -VITE_PRIVACY_POLICY_ACCEPT={{ .PrivacyPolicyAccept }} VITE_THEME={{ .Theme }} diff --git a/web/index.html b/web/index.html index ea719dfed..a40aa5f7f 100644 --- a/web/index.html +++ b/web/index.html @@ -13,14 +13,14 @@ diff --git a/web/vite.config.ts b/web/vite.config.ts index 659ba3e16..f045af5c0 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -1,5 +1,5 @@ import react from "@vitejs/plugin-react"; -import { defineConfig, loadEnv } from "vite"; +import { defineConfig } from "vite"; import eslintPlugin from "vite-plugin-eslint"; import istanbul from "vite-plugin-istanbul"; import svgr from "vite-plugin-svgr"; @@ -7,21 +7,9 @@ import tsconfigPaths from "vite-tsconfig-paths"; // @ts-ignore export default defineConfig(({ mode }) => { - const env = loadEnv(mode, "."); const isCoverage = process.env.VITE_COVERAGE === "true"; const sourcemap = isCoverage ? "inline" : undefined; - const htmlPlugin = () => { - return { - name: "html-transform", - transformIndexHtml(html: string) { - return html.replace(/%(.*?)%/g, function (match, p1) { - return env[p1]; - }); - }, - }; - }; - const istanbulPlugin = isCoverage ? istanbul({ include: "src/*", @@ -58,6 +46,6 @@ export default defineConfig(({ mode }) => { port: 3000, open: false, }, - plugins: [eslintPlugin({ cache: false }), htmlPlugin(), istanbulPlugin, react(), svgr(), tsconfigPaths()], + plugins: [eslintPlugin({ cache: false }), istanbulPlugin, react(), svgr(), tsconfigPaths()], }; });