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

Function shouldInline

packages/vite/src/node/plugins/asset.ts:536–566  ·  view source on GitHub ↗
(
  environment: Environment,
  file: string,
  id: string,
  content: Buffer,
  /** Should be passed only in build */
  buildPluginContext: PluginContext | undefined,
  forceInline: boolean | undefined,
)

Source from the content-addressed store, hash-verified

534}
535
536function shouldInline(
537 environment: Environment,
538 file: string,
539 id: string,
540 content: Buffer,
541 /** Should be passed only in build */
542 buildPluginContext: PluginContext | undefined,
543 forceInline: boolean | undefined,
544): boolean {
545 if (noInlineRE.test(id)) return false
546 if (inlineRE.test(id)) return true
547 // Do build only checks if passed the plugin context during build
548 if (buildPluginContext) {
549 if (environment.config.build.lib) return true
550 if (buildPluginContext.getModuleInfo(id)?.isEntry) return false
551 }
552 if (forceInline !== undefined) return forceInline
553 if (file.endsWith('.html')) return false
554 // Don't inline SVG with fragments, as they are meant to be reused
555 if (file.endsWith('.svg') && id.includes('#')) return false
556 let limit: number
557 const { assetsInlineLimit } = environment.config.build
558 if (typeof assetsInlineLimit === 'function') {
559 const userShouldInline = assetsInlineLimit(file, content)
560 if (userShouldInline != null) return userShouldInline
561 limit = DEFAULT_ASSETS_INLINE_LIMIT
562 } else {
563 limit = Number(assetsInlineLimit)
564 }
565 return content.length < limit && !isGitLfsPlaceholder(content)
566}
567
568function assetToDataURL(
569 environment: Environment,

Callers 2

fileToDevUrlFunction · 0.85
fileToBuiltUrlFunction · 0.85

Calls 3

isGitLfsPlaceholderFunction · 0.85
assetsInlineLimitFunction · 0.50
getModuleInfoMethod · 0.45

Tested by

no test coverage detected