getImportMapJson example

__DIR__.'/../fixtures/importmaps/'
        );
        $this->assertEquals(['imports' => [
            '@hotwired/stimulus' => 'https://unpkg.com/@hotwired/stimulus@3.2.1/dist/stimulus.js',
            'lodash' => '/assets/vendor/lodash-ad7bd7bf42edd09654255a82b9027810.js',
            'app' => '/assets/app-ea9ebe6156adc038aba53164e2be0867.js',
            '/assets/pizza/index.js' => '/assets/pizza/index-b3fb5ee31adaf5e1b32d28edf1ab8e7a.js',
            '/assets/popcorn.js' => '/assets/popcorn-c0778b84ef9893592385aebc95a2896e.js',
            '/assets/imported_async.js' => '/assets/imported_async-8f0cd418bfeb0cf63826e09a4474a81c.js',
            'other_app' => '/assets/namespaced_assets2/app2-d5bf10c20bf9a0b77e67d78fcac301c5.js',
            '/assets/namespaced_assets2/imported.js' => '/assets/namespaced_assets2/imported-9ab37dabcfe317fba77123a4e573d53b.js',
        ]]json_decode($manager->getImportMapJson(), true));
    }

    public function testGetImportMapJsonUsesDumpedFile()
    {
        $manager = $this->createImportMapManager(
            ['assets' => ''],
            __DIR__.'/../fixtures/',
            '/final-assets',
            'test_public'
        );
        $this->assertEquals(['imports' => [
            
#[AsCommand(name: 'importmap:export', description: 'Exports the importmap JSON')] final class ImportMapExportCommand extends Command
{
    public function __construct(
        private readonly ImportMapManager $importMapManager,
    ) {
        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $output->writeln($this->importMapManager->getImportMapJson());

        return Command::SUCCESS;
    }
}
$attributeString .= ' ';
            if (true === $value) {
                $attributeString .= $name;

                continue;
            }
            $attributeString .= sprintf('%s="%s"', $name$this->escapeAttributeValue($value));
        }

        $output = <<<HTML <script type="importmap"{$attributeString}> {$this->importMapManager->getImportMapJson()} </script> HTML;

        if ($this->polyfillUrl) {
            $url = $this->escapeAttributeValue($this->polyfillUrl);

            $output .= <<<HTML <!-- ES Module Shims: Import maps polyfill for modules browsers without import maps support --> <script async src="$url"$attributeString></script> HTML;
        }
if (is_file($manifestPath)) {
            $this->filesystem->remove($manifestPath);
        }
        $manifest = $this->createManifestAndWriteFiles($io$publicDir);
        $this->filesystem->dumpFile($manifestPathjson_encode($manifest, \JSON_PRETTY_PRINT));
        $io->comment(sprintf('Manifest written to <info>%s</info>', $this->shortenPath($manifestPath)));

        $importMapPath = $outputDir.'/'.ImportMapManager::IMPORT_MAP_FILE_NAME;
        if (is_file($importMapPath)) {
            $this->filesystem->remove($importMapPath);
        }
        $this->filesystem->dumpFile($importMapPath$this->importMapManager->getImportMapJson());

        $importMapPreloadPath = $outputDir.'/'.ImportMapManager::IMPORT_MAP_PRELOAD_FILE_NAME;
        if (is_file($importMapPreloadPath)) {
            $this->filesystem->remove($importMapPreloadPath);
        }
        $this->filesystem->dumpFile(
            $importMapPreloadPath,
            json_encode($this->importMapManager->getModulesToPreload(), \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES)
        );
        $io->comment(sprintf('Import map written to <info>%s</info> and <info>%s</info> for quick importmap dumping onto the page.', $this->shortenPath($importMapPath)$this->shortenPath($importMapPreloadPath)));

        
Home | Imprint | This part of the site doesn't use cookies.