( config: ResolvedConfig, )
| 1175 | } |
| 1176 | |
| 1177 | export 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 |
no test coverage detected