one
Version:
One is a React framework for web, iOS, and Android apps.
127 lines (124 loc) • 4.09 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var bundledDevPlugin_exports = {};
__export(bundledDevPlugin_exports, { bundledDevPlugin: () => bundledDevPlugin });
module.exports = __toCommonJS(bundledDevPlugin_exports);
var import_fs = __toESM(require("fs"), 1);
var import_path = __toESM(require("path"), 1);
var import_virtualEntryConstants = require("./virtualEntryConstants.native.js");
var MIME = {
png: "image/png",
jpg: "image/jpeg",
jpeg: "image/jpeg",
gif: "image/gif",
webp: "image/webp",
avif: "image/avif",
bmp: "image/bmp",
ico: "image/x-icon"
};
var ASSET_EXT_RE = /\.(png|jpe?g|gif|webp|avif|bmp|ico)/;
function inlineAssetImports(code, id) {
if (!ASSET_EXT_RE.test(code)) return null;
var importRe = /import\s+(\w+)\s+from\s*['"]([^'"?]+\.(?:png|jpe?g|gif|webp|avif|bmp|ico))['"]\s*;?/g;
var base = id.split("?")[0];
var result = code;
var changed = false;
var m;
var edits = [];
while (m = importRe.exec(code)) {
var [full, name, spec] = m;
var abs = spec.startsWith(".") ? import_path.default.resolve(import_path.default.dirname(base), spec) : null;
if (!abs || !import_fs.default.existsSync(abs)) continue;
var ext = import_path.default.extname(abs).slice(1).toLowerCase();
var uri = `data:${MIME[ext] || "application/octet-stream"};base64,${import_fs.default.readFileSync(abs).toString("base64")}`;
edits.push({
full,
name,
uri
});
}
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
try {
for (var _iterator = edits[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var e = _step.value;
result = result.replace(e.full, `const ${e.name} = ${JSON.stringify(e.uri)};`);
changed = true;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return changed ? {
code: result,
map: null
} : null;
}
function webBundledAssetPlugin() {
return {
name: "one:web-bundled-asset",
transform: function transform(code, id) {
return inlineAssetImports(code, id);
}
};
}
function bundledDevPlugin(enabled) {
return {
name: "one:bundled-dev",
...enabled ? { transform: {
filter: { code: ASSET_EXT_RE },
handler(code, id) {
var env = this.environment;
if (!env || env.name !== "ssr" || env.mode !== "dev") return;
return inlineAssetImports(code, id);
}
} } : {},
config(_userConfig, env) {
if (!enabled || env.command !== "serve") return;
return {
experimental: { bundledDev: true },
environments: { client: { build: { rolldownOptions: {
input: [import_virtualEntryConstants.virtualEntryId],
plugins: [webBundledAssetPlugin()],
experimental: { lazyBarrel: false },
shimMissingExports: true
} } } }
};
}
};
}
//# sourceMappingURL=bundledDevPlugin.native.js.map