Skip to content

Commit 673d608

Browse files
committed
BN-35 | Refactor. Build to use public path as /bahnew
1 parent 9eec7ec commit 673d608

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"start": "webpack serve --mode development --open",
7-
"build": "webpack --mode production",
7+
"build": "webpack --mode production --env PUBLIC_PATH='/bahnew/'",
88
"preview": "webpack serve --mode production --open",
99
"lint": "eslint --ext .ts,.tsx src/",
1010
"lint:fix": "eslint --ext .ts,.tsx src/ --fix",
@@ -86,4 +86,4 @@
8686
"yarn prettier:fix"
8787
]
8888
}
89-
}
89+
}

public/index.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<link rel="icon" href="/favicon.ico" />
65
<meta name="viewport" content="width=device-width, initial-scale=1" />
76
<meta name="theme-color" content="#0f62fe" />
87
<meta
98
name="description"
109
content="Bahmni Clinical Frontend Application"
1110
/>
12-
<link rel="apple-touch-icon" href="/logo192.png" />
13-
<link rel="manifest" href="/manifest.json" />
1411
<title>Bahmni Clinical</title>
1512
</head>
1613
<body>

src/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ import { BrowserRouter } from 'react-router-dom';
44
import App from './App';
55
import './styles/index.scss';
66

7+
const getBasename = () => {
8+
const pathname = window.location.pathname;
9+
const basePath = pathname.split('/').slice(0, 2).join('/');
10+
return basePath || '/';
11+
};
12+
713
// Register service worker for PWA
814
if ('serviceWorker' in navigator) {
915
window.addEventListener('load', () => {
1016
// Use a relative path that will work regardless of the base URL
11-
const swUrl = new URL('/service-worker.js', window.location.origin)
17+
const swUrl = new URL('./service-worker.js', window.location.href)
1218
.pathname;
1319

1420
navigator.serviceWorker
@@ -28,7 +34,7 @@ const root = createRoot(container);
2834

2935
root.render(
3036
<React.StrictMode>
31-
<BrowserRouter>
37+
<BrowserRouter basename={getBasename()}>
3238
<App />
3339
</BrowserRouter>
3440
</React.StrictMode>,

webpack.config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ const { GenerateSW } = require('workbox-webpack-plugin');
88

99
module.exports = (env, argv) => {
1010
const isProduction = argv.mode === 'production';
11+
// Allow configuring the public path via environment variable
12+
const publicPath = env.PUBLIC_PATH || '/';
1113

1214
return {
1315
entry: './src/index.tsx',
1416
output: {
1517
path: path.resolve(__dirname, 'dist'),
1618
filename: isProduction ? 'static/js/[name].[contenthash:8].js' : 'static/js/[name].js',
1719
chunkFilename: isProduction ? 'static/js/[name].[contenthash:8].chunk.js' : 'static/js/[name].chunk.js',
18-
publicPath: '/',
20+
publicPath: publicPath,
1921
clean: true,
2022
},
2123
devtool: isProduction ? 'source-map' : 'cheap-module-source-map',
@@ -113,8 +115,8 @@ module.exports = (env, argv) => {
113115
theme_color: '#0f62fe', // Carbon blue
114116
display: 'standalone',
115117
orientation: 'portrait',
116-
scope: '/',
117-
start_url: '/',
118+
scope: publicPath,
119+
start_url: publicPath,
118120
icons: [
119121
{
120122
src: path.resolve('public/logo512.png'),

0 commit comments

Comments
 (0)