| 10 | return { |
| 11 | name: 'version-injection', |
| 12 | transformIndexHtml(html) { |
| 13 | try { |
| 14 | // Read the generated version info injection script |
| 15 | const injectionScriptPath = path.resolve(__dirname, 'src/generated/version-injection.html'); |
| 16 | |
| 17 | if (fs.existsSync(injectionScriptPath)) { |
| 18 | const injectionScript = fs.readFileSync(injectionScriptPath, 'utf-8'); |
| 19 | |
| 20 | // Inject the version info script before </head> |
| 21 | return html.replace('</head>', `${injectionScript}\n</head>`); |
| 22 | } |
| 23 | |
| 24 | console.warn('[version-injection] Version injection script not found, skipping injection'); |
| 25 | return html; |
| 26 | } catch (error) { |
| 27 | console.error('[version-injection] Failed to inject version info:', error); |
| 28 | return html; |
| 29 | } |
| 30 | } |
| 31 | }; |
| 32 | } |
| 33 | |