getModulesToPreload example


        $manager = $this->createImportMapManager(
            ['assets' => '', 'assets2' => 'namespaced_assets2'],
            __DIR__.'/../fixtures/importmaps/'
        );
        $this->assertEquals([
            'https://unpkg.com/@hotwired/stimulus@3.2.1/dist/stimulus.js',
            '/assets/app-ea9ebe6156adc038aba53164e2be0867.js',
            // these are non-lazily imported from app.js             '/assets/pizza/index-b3fb5ee31adaf5e1b32d28edf1ab8e7a.js',
            '/assets/popcorn-c0778b84ef9893592385aebc95a2896e.js',
        ]$manager->getModulesToPreload());
    }

    public function testGetImportMapJson()
    {
        $manager = $this->createImportMapManager(
            ['assets' => '', 'assets2' => 'namespaced_assets2'],
            __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',
            
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)));

        if ($this->isDebug) {
            $io->warning(sprintf(
                'You are compiling assets in development. Symfony will not serve any changed assets until you delete the "%s" directory.',
                $this->shortenPath($outputDir)
            ));
        }

        return 0;
    }
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;
        }

        foreach ($this->importMapManager->getModulesToPreload() as $url) {
            $url = $this->escapeAttributeValue($url);

            $output .= "\n<link rel=\"modulepreload\" href=\"{$url}\">";
        }

        if (null !== $entryPoint) {
            $output .= "\n<script type=\"module\"$attributeString>import '".str_replace("'", "\\'", $entryPoint)."';</script>";
        }

        return $output;
    }

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