Skip to content

Commit

Permalink
Fix gh-pages base route
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Oct 1, 2023
1 parent f5f5fa2 commit 9e6a677
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 27 deletions.
Empty file removed .env
Empty file.
1 change: 1 addition & 0 deletions .env.gh-pages
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_GH_PAGES_BUILD=true
2 changes: 1 addition & 1 deletion .github/workflows/deploy-demo-to-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
run: npm ci

- name: Build
run: npm run build-mock
run: npm run build:gh-pages

- name: Deploy
if: ${{ github.event_name != 'pull_request' }}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"start": "vite",
"start-mock": "vite --mode mock",
"build": "vite build",
"build-mock": "vite build --mode mock",
"build:gh-pages": "vite build --mode gh-pages",
"build-and-zip": "vite build && ./script/zip-dist.sh",
"init-mock": "npx msw init public --no-save",
"prettier": "npx prettier --write \"src/**/*.{ts,tsx}\"",
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "./i18n/i18n";
import "./index.css";

console.log("Running in:", import.meta.env.MODE);
if (import.meta.env.MODE === "mock") {
if (import.meta.env.MODE === "mock" || import.meta.env.MODE === "gh-pages") {
worker.start();
}

Expand Down
56 changes: 32 additions & 24 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
import { defineConfig } from "vite";
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react";
const path = require("path");

export default defineConfig({
server: {
proxy: {
"/api/v1": {
target: "http://localhost:8080/api/v1",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api\/v1/, ""),
const viteConfig = ({ mode }) => {
const isGhPagesBuild =
loadEnv(mode, process.cwd()).VITE_GH_PAGES_BUILD === "true";

return defineConfig({
server: {
proxy: {
"/api/v1": {
target: "http://localhost:8080/api/v1",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api\/v1/, ""),
},
},
},
},
build: {
// https://stackoverflow.com/questions/76694615/module-level-directives-cause-errors-when-bundled-use-client-was-ignored-caus
rollupOptions: {
onwarn(warning, warn) {
if (warning.code === "MODULE_LEVEL_DIRECTIVE") {
return;
}
warn(warning);
base: isGhPagesBuild ? "/oj-lab-front/" : "/",
build: {
// https://stackoverflow.com/questions/76694615/module-level-directives-cause-errors-when-bundled-use-client-was-ignored-caus
rollupOptions: {
onwarn(warning, warn) {
if (warning.code === "MODULE_LEVEL_DIRECTIVE") {
return;
}
warn(warning);
},
},
},
},
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
},
});
});
};

export default viteConfig;

0 comments on commit 9e6a677

Please sign in to comment.