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

Function preImportMapHook

packages/vite/src/node/plugins/html.ts:1177–1200  ·  view source on GitHub ↗
(
  config: ResolvedConfig,
)

Source from the content-addressed store, hash-verified

1175 }
1176
1177export function preImportMapHook(
1178 config: ResolvedConfig,
1179): IndexHtmlTransformHook {
1180 return (html, ctx) => {
1181 const importMapIndex = html.search(importMapRE)
1182 if (importMapIndex < 0) return
1183
1184 const importMapAppendIndex = html.search(importMapAppendRE)
1185 if (importMapAppendIndex < 0) return
1186
1187 if (importMapAppendIndex < importMapIndex) {
1188 const relativeHtml = normalizePath(
1189 path.relative(config.root, ctx.filename),
1190 )
1191 config.logger.warnOnce(
1192 colors.yellow(
1193 colors.bold(
1194 `(!) <script type="importmap"> should come before <script type="module"> and <link rel="modulepreload"> in /${relativeHtml}`,
1195 ),
1196 ),
1197 )
1198 }
1199 }
1200}
1201
1202/**
1203 * Move importmap before the first module script and modulepreload link

Callers 2

createDevHtmlTransformFnFunction · 0.90
buildHtmlPluginFunction · 0.85

Calls 2

normalizePathFunction · 0.90
warnOnceMethod · 0.65

Tested by

no test coverage detected