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.entrypoints=https'
- 'traefik.http.routers.authelia_frontend.tls=true' - 'traefik.http.routers.authelia_frontend.tls=true'
environment: environment:
- VITE_PUBLIC_URL=${PathPrefix} - VITE_BASEPATH=${PathPrefix}
networks: networks:
- authelianet - authelianet
... ...

View File

@ -1,9 +1,9 @@
VITE_LOGO_OVERRIDE={{ .LogoOverride }} VITE_BASEPATH={{ .Base }}
VITE_PUBLIC_URL={{ .Base }}
VITE_DUO_SELF_ENROLLMENT={{ .DuoSelfEnrollment }} VITE_DUO_SELF_ENROLLMENT={{ .DuoSelfEnrollment }}
VITE_LOGO_OVERRIDE={{ .LogoOverride }}
VITE_PRIVACY_POLICY_ACCEPT={{ .PrivacyPolicyAccept }}
VITE_PRIVACY_POLICY_URL={{ .PrivacyPolicyURL }}
VITE_REMEMBER_ME={{ .RememberMe }} VITE_REMEMBER_ME={{ .RememberMe }}
VITE_RESET_PASSWORD={{ .ResetPassword }} VITE_RESET_PASSWORD={{ .ResetPassword }}
VITE_RESET_PASSWORD_CUSTOM_URL={{ .ResetPasswordCustomURL }} VITE_RESET_PASSWORD_CUSTOM_URL={{ .ResetPasswordCustomURL }}
VITE_PRIVACY_POLICY_URL={{ .PrivacyPolicyURL }}
VITE_PRIVACY_POLICY_ACCEPT={{ .PrivacyPolicyAccept }}
VITE_THEME={{ .Theme }} VITE_THEME={{ .Theme }}

View File

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

View File

@ -1,5 +1,5 @@
import react from "@vitejs/plugin-react"; import react from "@vitejs/plugin-react";
import { defineConfig, loadEnv } from "vite"; import { defineConfig } from "vite";
import eslintPlugin from "vite-plugin-eslint"; import eslintPlugin from "vite-plugin-eslint";
import istanbul from "vite-plugin-istanbul"; import istanbul from "vite-plugin-istanbul";
import svgr from "vite-plugin-svgr"; import svgr from "vite-plugin-svgr";
@ -7,21 +7,9 @@ import tsconfigPaths from "vite-tsconfig-paths";
// @ts-ignore // @ts-ignore
export default defineConfig(({ mode }) => { export default defineConfig(({ mode }) => {
const env = loadEnv(mode, ".");
const isCoverage = process.env.VITE_COVERAGE === "true"; const isCoverage = process.env.VITE_COVERAGE === "true";
const sourcemap = isCoverage ? "inline" : undefined; 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 const istanbulPlugin = isCoverage
? istanbul({ ? istanbul({
include: "src/*", include: "src/*",
@ -58,6 +46,6 @@ export default defineConfig(({ mode }) => {
port: 3000, port: 3000,
open: false, open: false,
}, },
plugins: [eslintPlugin({ cache: false }), htmlPlugin(), istanbulPlugin, react(), svgr(), tsconfigPaths()], plugins: [eslintPlugin({ cache: false }), istanbulPlugin, react(), svgr(), tsconfigPaths()],
}; };
}); });