MCPcopy
hub / github.com/vitejs/vite / toScriptTag

Function toScriptTag

packages/vite/src/node/plugins/html.ts:850–871  ·  view source on GitHub ↗
(
        chunkOrUrl: OutputChunk | string,
        toOutputPath: (filename: string) => string,
        isAsync: boolean,
      )

Source from the content-addressed store, hash-verified

848 }
849
850 const toScriptTag = (
851 chunkOrUrl: OutputChunk | string,
852 toOutputPath: (filename: string) => string,
853 isAsync: boolean,
854 ): HtmlTagDescriptor => ({
855 tag: 'script',
856 attrs: {
857 ...(isAsync ? { async: true } : {}),
858 type: 'module',
859 // crossorigin must be set not only for serving assets in a different origin
860 // but also to make it possible to preload the script using `<link rel="preload">`.
861 // `<script type="module">` used to fetch the script with credential mode `omit`,
862 // however `crossorigin` attribute cannot specify that value.
863 // https://developer.chrome.com/blog/modulepreload/#ok-so-why-doesnt-link-relpreload-work-for-modules:~:text=For%20%3Cscript%3E,of%20other%20modules.
864 // Now `<script type="module">` uses `same origin`: https://github.com/whatwg/html/pull/3656#:~:text=Module%20scripts%20are%20always%20fetched%20with%20credentials%20mode%20%22same%2Dorigin%22%20by%20default%20and%20can%20no%20longer%0Ause%20%22omit%22
865 crossorigin: true,
866 src:
867 typeof chunkOrUrl === 'string'
868 ? chunkOrUrl
869 : toOutputPath(chunkOrUrl.fileName),
870 },
871 })
872
873 const toPreloadTag = (
874 filename: string,

Callers 1

generateBundleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected