|
1 | 1 | <!DOCTYPE html> |
2 | 2 | <!-- |
3 | | - YASGUI Graph Plugin - Live Development Demo |
| 3 | + YASGUI Graph Plugin - Demo Page |
4 | 4 | |
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/ |
7 | 8 | |
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 |
9 | 11 | --> |
10 | 12 | <html lang="en"> |
11 | 13 | <head> |
@@ -143,33 +145,42 @@ <h2 onclick="toggleInstructions()"> |
143 | 145 |
|
144 | 146 | <!-- Graph Plugin: Load from source in dev, or from dist in production --> |
145 | 147 | <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 | + |
147 | 154 | 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'); |
154 | 167 | } |
155 | | - } catch (error) { |
156 | | - console.log('Source not available, loading from bundle (production mode)'); |
157 | 168 | } |
158 | 169 |
|
159 | | - // Fall back to bundle if source didn't work |
| 170 | + // In production mode or if dev load failed, load the bundle |
160 | 171 | if (!pluginLoaded) { |
161 | 172 | const script = document.createElement('script'); |
162 | | - script.src = './dist/yasgui-graph-plugin.min.js'; |
163 | 173 | await new Promise((resolve, reject) => { |
164 | 174 | script.onload = () => { |
165 | | - console.log('Graph Plugin loaded from bundle'); |
| 175 | + console.log('✅ Graph Plugin loaded from bundle (production mode)'); |
166 | 176 | resolve(); |
167 | 177 | }; |
168 | 178 | script.onerror = () => { |
169 | | - console.error('Failed to load Graph Plugin bundle'); |
| 179 | + console.error('❌ Failed to load Graph Plugin bundle'); |
170 | 180 | reject(); |
171 | 181 | }; |
172 | 182 | document.head.appendChild(script); |
| 183 | + script.src = './dist/yasgui-graph-plugin.min.js'; |
173 | 184 | }); |
174 | 185 | } |
175 | 186 |
|
|
0 commit comments