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

Function addInlineModule

packages/vite/src/node/server/middlewares/indexHtml.ts:245–280  ·  view source on GitHub ↗
(
    node: DefaultTreeAdapterMap['element'],
    ext: 'js',
  )

Source from the content-addressed store, hash-verified

243 const inlineModulePaths: string[] = []
244
245 const addInlineModule = (
246 node: DefaultTreeAdapterMap['element'],
247 ext: 'js',
248 ) => {
249 inlineModuleIndex++
250
251 const contentNode = node.childNodes[0] as DefaultTreeAdapterMap['textNode']
252
253 const code = contentNode.value
254
255 let map: SourceMapInput | undefined
256 if (proxyModulePath[0] !== '\0') {
257 map = new MagicString(html)
258 .snip(
259 contentNode.sourceCodeLocation!.startOffset,
260 contentNode.sourceCodeLocation!.endOffset,
261 )
262 .generateMap({ hires: 'boundary' })
263 map.sources = [filename]
264 map.file = filename
265 }
266
267 // add HTML Proxy to Map
268 addToHTMLProxyCache(config, proxyCacheUrl, inlineModuleIndex, { code, map })
269
270 // inline js module. convert to src="proxy" (dev only, base is never relative)
271 const modulePath = `${proxyModuleUrl}?html-proxy&index=${inlineModuleIndex}.${ext}`
272 inlineModulePaths.push(modulePath)
273
274 s.update(
275 node.sourceCodeLocation!.startOffset,
276 node.sourceCodeLocation!.endOffset,
277 `<script type="module" src="${modulePath}"></script>`,
278 )
279 preTransformRequest(server!, modulePath, decodedBase)
280 }
281
282 await traverseHtml(html, filename, config.logger.warn, (node) => {
283 if (!nodeIsElement(node)) {

Callers 1

devHtmlHookFunction · 0.85

Calls 2

addToHTMLProxyCacheFunction · 0.90
preTransformRequestFunction · 0.85

Tested by

no test coverage detected