Skip to content

Commit 6ef3553

Browse files
authored
Merge pull request #6 from Matdata-eu/copilot/fix-github-pages-deployment
Fix demo page loading on GitHub Pages with environment detection
2 parents 3494f31 + c33c1f9 commit 6ef3553

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

demo/index.html

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<!DOCTYPE html>
22
<!--
3-
YASGUI Graph Plugin - Live Development Demo
3+
YASGUI Graph Plugin - Demo Page
44
5-
This demo loads ES modules directly from src/ for instant live reload.
6-
Edit any source file (e.g., src/colorUtils.js) and refresh to see changes!
5+
This demo automatically detects the environment:
6+
- Development (localhost/file): Loads ES modules from src/ for live reload
7+
- Production (GitHub Pages): Loads minified bundle from dist/
78
8-
For production builds, run: npm run build
9+
To develop locally: Open this file directly or run: npm run dev
10+
For production builds: npm run build
911
-->
1012
<html lang="en">
1113
<head>
@@ -143,33 +145,42 @@ <h2 onclick="toggleInstructions()">
143145

144146
<!-- Graph Plugin: Load from source in dev, or from dist in production -->
145147
<script type="module">
146-
// Try to load from source (development mode)
148+
// Detect if we're in development mode by checking if running on localhost/file protocol
149+
const isDev = window.location.hostname === 'localhost' ||
150+
window.location.hostname === '127.0.0.1' ||
151+
window.location.hostname === '[::1]' ||
152+
window.location.protocol === 'file:';
153+
147154
let pluginLoaded = false;
148-
try {
149-
const { default: GraphPlugin } = await import('../src/GraphPlugin.js');
150-
if (window.Yasgui && window.Yasgui.Yasr) {
151-
window.Yasgui.Yasr.registerPlugin('Graph-dev', GraphPlugin);
152-
pluginLoaded = true;
153-
console.log('Graph Plugin loaded from source (dev mode)');
155+
156+
// In development mode, try to load from source
157+
if (isDev) {
158+
try {
159+
const { default: GraphPlugin } = await import('../src/GraphPlugin.js');
160+
if (window.Yasgui && window.Yasgui.Yasr) {
161+
window.Yasgui.Yasr.registerPlugin('Graph', GraphPlugin);
162+
pluginLoaded = true;
163+
console.log('✅ Graph Plugin loaded from source (dev mode)');
164+
}
165+
} catch (error) {
166+
console.log('⚠️ Source not available, falling back to bundle');
154167
}
155-
} catch (error) {
156-
console.log('Source not available, loading from bundle (production mode)');
157168
}
158169

159-
// Fall back to bundle if source didn't work
170+
// In production mode or if dev load failed, load the bundle
160171
if (!pluginLoaded) {
161172
const script = document.createElement('script');
162-
script.src = './dist/yasgui-graph-plugin.min.js';
163173
await new Promise((resolve, reject) => {
164174
script.onload = () => {
165-
console.log('Graph Plugin loaded from bundle');
175+
console.log('Graph Plugin loaded from bundle (production mode)');
166176
resolve();
167177
};
168178
script.onerror = () => {
169-
console.error('Failed to load Graph Plugin bundle');
179+
console.error('Failed to load Graph Plugin bundle');
170180
reject();
171181
};
172182
document.head.appendChild(script);
183+
script.src = './dist/yasgui-graph-plugin.min.js';
173184
});
174185
}
175186

0 commit comments

Comments
 (0)