From 92e7fc208571151c81cb24519b4912831baa6151 Mon Sep 17 00:00:00 2001 From: shellyear Date: Sat, 13 Apr 2024 19:36:51 +0500 Subject: [PATCH 1/2] [fix] build 'route/:id' refresh issue by removing explicit 'base' from vite.config.js (default is '/') --- vite.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/vite.config.js b/vite.config.js index 46e6d61c..5a005ed5 100644 --- a/vite.config.js +++ b/vite.config.js @@ -7,7 +7,6 @@ import eslintPlugin from "vite-plugin-eslint"; dotenv.config(); export default defineConfig({ - base: "", root: "", envPrefix: "RECORD_MANAGER_", plugins: [ From feec894dffcd4a994633ab4e7204f93ee9b49bb8 Mon Sep 17 00:00:00 2001 From: shellyear Date: Thu, 18 Apr 2024 21:49:38 +0500 Subject: [PATCH 2/2] [fix] set new basename for the production, use base for vite depending on the environment; --- .env.production | 2 +- vite.config.js | 98 ++++++++++++++++++++++++++++--------------------- 2 files changed, 57 insertions(+), 43 deletions(-) diff --git a/.env.production b/.env.production index e862a1c8..71c5bd68 100644 --- a/.env.production +++ b/.env.production @@ -3,6 +3,6 @@ RECORD_MANAGER_APP_TITLE=Record Manager Prod RECORD_MANAGER_APP_INFO= RECORD_MANAGER_LANGUAGE=cs RECORD_MANAGER_NAVIGATOR_LANGUAGE=true -RECORD_MANAGER_BASENAME=/ +RECORD_MANAGER_BASENAME=/record-manager RECORD_MANAGER_EXTENSIONS=supplier RECORD_MANAGER_AUTHENTICATION=internal \ No newline at end of file diff --git a/vite.config.js b/vite.config.js index 5a005ed5..4ee8e522 100644 --- a/vite.config.js +++ b/vite.config.js @@ -3,53 +3,67 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import dotenv from "dotenv"; import eslintPlugin from "vite-plugin-eslint"; +import { resolve } from "path"; +import { readFileSync } from "fs"; dotenv.config(); -export default defineConfig({ - root: "", - envPrefix: "RECORD_MANAGER_", - plugins: [ - react(), - eslintPlugin({ - cache: false, - }), - ], - build: { - sourcemap: true, - emptyOutDir: true, - rollupOptions: { - onwarn: (warning, defaultHandler) => { - // TODO: workaround for dangerous use of eval method that should be solved in SForms library issue https://github.com/kbss-cvut/s-forms/issues/283 - const isFromKbssCvutPackageWarning = - warning.code === "EVAL" && warning.message.includes("node_modules/store/plugins/lib/json2.js"); - // TODO: Rollup Pure Annotation warning should be resolved by https://github.com/kbss-cvut/s-forms/issues/282 - const isRollupPureAnnotationWarning = - warning.code === "INVALID_ANNOTATION" && warning.message.includes("*#__PURE__*"); - if (isFromKbssCvutPackageWarning || isRollupPureAnnotationWarning) { - return; - } - defaultHandler(warning); +function loadEnv(mode) { + const envPath = resolve(process.cwd(), `.env.${mode}`); + const envContent = readFileSync(envPath, "utf-8"); + const env = dotenv.parse(envContent); + return env; +} + +export default ({ mode }) => { + const env = loadEnv(mode); + + return defineConfig({ + base: env.RECORD_MANAGER_BASENAME, + root: "", + envPrefix: "RECORD_MANAGER_", + plugins: [ + react(), + eslintPlugin({ + cache: false, + }), + ], + build: { + sourcemap: true, + emptyOutDir: true, + rollupOptions: { + onwarn: (warning, defaultHandler) => { + // TODO: workaround for dangerous use of eval method that should be solved in SForms library issue https://github.com/kbss-cvut/s-forms/issues/283 + const isFromKbssCvutPackageWarning = + warning.code === "EVAL" && warning.message.includes("node_modules/store/plugins/lib/json2.js"); + // TODO: Rollup Pure Annotation warning should be resolved by https://github.com/kbss-cvut/s-forms/issues/282 + const isRollupPureAnnotationWarning = + warning.code === "INVALID_ANNOTATION" && warning.message.includes("*#__PURE__*"); + if (isFromKbssCvutPackageWarning || isRollupPureAnnotationWarning) { + return; + } + defaultHandler(warning); + }, }, + cssMinify: false, // TODO: workaround for CSS syntax error from SForms library that should be resolved by https://github.com/kbss-cvut/s-forms/issues/283 }, - cssMinify: false, // TODO: workaround for CSS syntax error from SForms library that should be resolved by https://github.com/kbss-cvut/s-forms/issues/283 - }, - define: { - "process.env": process.env, // workaround for parse-link-header library that depends on 2 vars defined in `process.env`, see https://github.com/thlorenz/parse-link-header/issues/31 - }, - resolve: { - alias: { - querystring: "querystring-es3", // workaround for parse-link-header library that replaces nodejs builtin module with the module adapted for browser - url: "url-parse", // workaround for parse-link-header library that replaces nodejs builtin module with the module adapted for browser + define: { + "process.env": process.env, // workaround for parse-link-header library that depends on 2 vars defined in `process.env`, see https://github.com/thlorenz/parse-link-header/issues/31 + }, + resolve: { + alias: { + querystring: "querystring-es3", // workaround for parse-link-header library that replaces nodejs builtin module with the module adapted for browser + url: "url-parse", // workaround for parse-link-header library that replaces nodejs builtin module with the module adapted for browser + }, }, - }, - test: { - environment: "jsdom", - setupFiles: ["./tests/setup.js"], - server: { - deps: { - inline: ["@kbss-cvut/s-forms"], + test: { + environment: "jsdom", + setupFiles: ["./tests/setup.js"], + server: { + deps: { + inline: ["@kbss-cvut/s-forms"], + }, }, }, - }, -}); + }); +};