UNPKG

one

Version:

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

89 lines (87 loc) 2.79 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var criticalCSSPlugin_exports = {}; __export(criticalCSSPlugin_exports, { criticalCSSPlugin: () => criticalCSSPlugin, getCriticalCSSOutputPaths: () => getCriticalCSSOutputPaths, getCriticalCSSSources: () => getCriticalCSSSources }); module.exports = __toCommonJS(criticalCSSPlugin_exports); var import_path = require("path"); var INLINE_CSS_EXT = ".inline.css"; var criticalCSSSources = /* @__PURE__ */new Set(); var root = ""; function getCriticalCSSSources() { return criticalCSSSources; } function getCriticalCSSOutputPaths(clientManifest) { var outputPaths = /* @__PURE__ */new Set(); var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; try { for (var _iterator = Object.entries(clientManifest)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var [sourceKey, entry] = _step.value; if (sourceKey.endsWith(".css") && criticalCSSSources.has(sourceKey)) { outputPaths.add(`/${entry.file}`); } } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } return outputPaths; } function criticalCSSPlugin() { return { name: "one:critical-css", enforce: "pre", configResolved(config) { root = config.root; }, async resolveId(id, importer) { if (!id.endsWith(INLINE_CSS_EXT)) return null; var resolved = await this.resolve(id, importer, { skipSelf: true }); if (resolved) { var relativePath = (0, import_path.relative)(root, resolved.id); criticalCSSSources.add(relativePath); return resolved; } return null; } }; } //# sourceMappingURL=criticalCSSPlugin.native.js.map