HEX
Server: Apache/2.4.65 (Debian)
System: Linux 88f31f35b0b8 6.1.0-38-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.147-1 (2025-08-02) x86_64
User: www-data (33)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/wp-rss-aggregator/core/modules/devServer.php
<?php

namespace RebelCode\Aggregator\Core;

wpra()->addModule(
	'devServer',
	array( 'admin.frame.l10n' ),
	function ( callable $getL10n ) {
		$wpra = wpra();

		$url = apply_filters( 'wpra.devServer.url', 'http://localhost:5173' );
		$enabled = apply_filters( 'wpra.devServer.enabled', ! is_dir( "{$wpra->path}/core/js/dist" ) );

		// Inject vite runtime and other stuff in the <head>
		add_filter(
			'wpra.admin.frame.head',
			function ( string $output ) use ( $enabled, $url ) {
				if ( ! $enabled ) {
					return $output;
				}
				return $output . <<<HTML
            <script>const global = globalThis</script>
            <script type="module">
            import RefreshRuntime from "{$url}/@react-refresh"
            RefreshRuntime.injectIntoGlobalHook(window)
            window.\$RefreshReg\$ = () => {}
            window.\$RefreshSig\$ = () => (type) => type
            window.__vite_plugin_react_preamble_installed__ = true
            </script>
            <script type="module" src="{$url}/@vite/client"></script>
            HTML;
			}
		);

		// Enqueue app module and manually localized config
		add_filter(
			'wpra.admin.frame.body.end',
			function ( string $output ) use ( $enabled, $url, $getL10n ) {
				if ( ! $enabled ) {
					return $output;
				}

				$l10n = $getL10n();
				$varName = $l10n->name;
				$varVal = wp_json_encode( $l10n->data );

				return <<<HTML
            <script type="text/javascript">
                var {$varName} = {$varVal};
            </script>
            <script type="module" src="{$url}/core/js/src/admin/index.tsx"></script>
            HTML;
			}
		);
	}
);