UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

45 lines (44 loc) 1.28 kB
import { relative } from "node:path"; import { normalizePath } from "vite"; const INLINE_CSS_RE = /\.inline\.css$/; const criticalCSSSources = /* @__PURE__ */new Set(); let root = ""; function getCriticalCSSSources() { return criticalCSSSources; } function getCriticalCSSOutputPaths(clientManifest) { const outputPaths = /* @__PURE__ */new Set(); for (const [sourceKey, entry] of Object.entries(clientManifest)) { if (sourceKey.endsWith(".css") && criticalCSSSources.has(sourceKey)) { outputPaths.add(`/${entry.file}`); } } return outputPaths; } function criticalCSSPlugin() { return { name: "one:critical-css", enforce: "pre", configResolved(config) { root = config.root; }, resolveId: { filter: { id: INLINE_CSS_RE }, async handler(id, importer) { const resolved = await this.resolve(id, importer, { skipSelf: true }); if (resolved) { const relativePath = normalizePath(relative(root, resolved.id)); criticalCSSSources.add(relativePath); return resolved; } return null; } } }; } export { criticalCSSPlugin, getCriticalCSSOutputPaths, getCriticalCSSSources }; //# sourceMappingURL=criticalCSSPlugin.mjs.map