@resource-fallback/core / index
index
Functions
buildInjectedTags()
function buildInjectedTags(opts): HtmlTag[];Defined in: index.ts:131
构建所有需要注入到 HTML 中的 <script> / <link> 标签描述。 webpack 和 vite 插件都调用此函数以确保输出一致的标记。
运行时配置被 JSON 序列化并内联;仅原始类型的匹配器(string / RegExp)会被保留。 函数形式的 match 需要通过 defaults 传入或手动初始化运行时。
Parameters
opts
ExtendedPluginOptions
Returns
HtmlTag[]
defineConfig()
function defineConfig<T>(config): T;Defined in: index.ts:44
恒等辅助函数——让用户在编写配置时获得类型检查和 IDE 悬浮提示。
Type Parameters
T
T extends PluginOptions
Parameters
config
T
Returns
T
Example
import { defineConfig } from '@resource-fallback/core';
export default defineConfig({ rules: [...] });getRuntimeCode()
function getRuntimeCode(): string;Defined in: index.ts:77
读取 IIFE 运行时文件内容。首次调用后缓存。
Returns
string
getRuntimePath()
function getRuntimePath(): string;Defined in: index.ts:49
返回 IIFE 运行时文件的绝对路径。
Returns
string
getServiceWorkerCode()
function getServiceWorkerCode(): string;Defined in: index.ts:108
读取 Service Worker 运行时代码。源码测试环境未构建时返回占位代码。
Returns
string
getServiceWorkerPath()
function getServiceWorkerPath(): string;Defined in: index.ts:85
返回 Service Worker 运行时文件的绝对路径。
Returns
string
joinAssetPrefix()
function joinAssetPrefix(prefix, filename): string;Defined in: index.ts:197
拼接 asset 前缀与文件名。
- 绝对 URL(
https?://或/开头)直接返回 filename - 空 filename 返回 prefix(标准化尾部斜杠)
- 去掉 filename 的前导
/,确保 prefix 与 filename 之间恰好一个/
Parameters
prefix
string
filename
string
Returns
string
serialiseConfig()
function serialiseConfig(cfg): string;Defined in: index.ts:184
将运行时配置序列化为 JSON,其中 RegExp 实例会被渲染为原生正则字面量, 以便运行时直接使用。
Parameters
cfg
RuntimeConfig & object
Returns
string
References
buildResourceFallbackManifest
Re-exports buildResourceFallbackManifest
buildServiceWorkerAssets
Re-exports buildServiceWorkerAssets
CircuitOptions
Re-exports CircuitOptions
ErrorEvent
Re-exports ErrorEvent
FallbackEvent
Re-exports FallbackEvent
FallbackRule
Re-exports FallbackRule
HtmlTag
Re-exports HtmlTag
HtmlTagAttributes
Re-exports HtmlTagAttributes
inferResourceFallbackAssetType
Re-exports inferResourceFallbackAssetType
MatchPattern
Re-exports MatchPattern
NormalizedServiceWorkerOptions
Re-exports NormalizedServiceWorkerOptions
normalizeServiceWorkerOptions
Re-exports normalizeServiceWorkerOptions
PluginOptions
Re-exports PluginOptions
ResolveResult
Re-exports ResolveResult
ResourceFallbackAssetOwner
Re-exports ResourceFallbackAssetOwner
ResourceFallbackAssetType
Re-exports ResourceFallbackAssetType
ResourceFallbackManifest
Re-exports ResourceFallbackManifest
ResourceFallbackManifestAsset
Re-exports ResourceFallbackManifestAsset
RetryEvent
Re-exports RetryEvent
RetryOptions
Re-exports RetryOptions
RuntimeConfig
Re-exports RuntimeConfig
RuntimeHooks
Re-exports RuntimeHooks
ServiceWorkerOptions
Re-exports ServiceWorkerOptions
SriPolicy
Re-exports SriPolicy
SuccessEvent
Re-exports SuccessEvent