astro
Version:
Astro is a modern site builder with web best practices, performance, and DX front-of-mind.
40 lines (39 loc) • 1 kB
JavaScript
function fromEntries(entries) {
const obj = {};
for (const [k, v] of entries) {
obj[k] = v;
}
return obj;
}
export function addRolldownInput(inputOptions, newInputs) {
// Add input module ids to existing input option, whether it's a string, array or object
// this way you can use multiple html plugins all adding their own inputs
if (!inputOptions.input) {
return {
...inputOptions,
input: newInputs
};
}
if (typeof inputOptions.input === "string") {
return {
...inputOptions,
input: [inputOptions.input, ...newInputs]
};
}
if (Array.isArray(inputOptions.input)) {
return {
...inputOptions,
input: [...inputOptions.input, ...newInputs]
};
}
if (typeof inputOptions.input === "object") {
return {
...inputOptions,
input: {
...inputOptions.input,
...fromEntries(newInputs.map((i) => [i.split("/").slice(-1)[0].split(".")[0], i]))
}
};
}
throw new Error(`Unknown rolldown input type. Supported inputs are string, array and object.`);
}