refactor(web): native vite env replacement (#5078)

pull/5080/head
Amir Zarrinkafsh 2023-03-17 16:50:27 +11:00 committed by GitHub
parent b317095f60
commit 496dee6e42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 22 deletions

View File

@ -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
...

View File

@ -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 }}

View File

@ -13,14 +13,14 @@
</head>
<body
data-basepath="%VITE_PUBLIC_URL%"
data-basepath="%VITE_BASEPATH%"
data-duoselfenrollment="%VITE_DUO_SELF_ENROLLMENT%"
data-logooverride="%VITE_LOGO_OVERRIDE%"
data-privacypolicyaccept="%VITE_PRIVACY_POLICY_ACCEPT%"
data-privacypolicyurl="%VITE_PRIVACY_POLICY_URL%"
data-rememberme="%VITE_REMEMBER_ME%"
data-resetpassword="%VITE_RESET_PASSWORD%"
data-resetpasswordcustomurl="%VITE_RESET_PASSWORD_CUSTOM_URL%"
data-privacypolicyurl="%VITE_PRIVACY_POLICY_URL%"
data-privacypolicyaccept="%VITE_PRIVACY_POLICY_ACCEPT%"
data-theme="%VITE_THEME%"
>
<noscript>You need to enable JavaScript to run this app.</noscript>

View File

@ -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()],
};
});