( environment: Environment, file: string, id: string, content: Buffer, /** Should be passed only in build */ buildPluginContext: PluginContext | undefined, forceInline: boolean | undefined, )
| 534 | } |
| 535 | |
| 536 | function 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 | |
| 568 | function assetToDataURL( |
| 569 | environment: Environment, |
no test coverage detected