vite-plugin-storybook-nextjs
Version:
This is a Vite plugin that allows you to use Next.js features in Vite. It is the basis for `@storybook/experimental-nextjs-vite` and should be used when running portable stories in Vitest.
41 lines (38 loc) • 1.01 kB
JavaScript
;
// src/plugins/next-image/alias/image-default-loader.tsx
var defaultLoader = ({
src,
width,
quality = 75
}) => {
const missingValues = [];
if (!src) {
missingValues.push("src");
}
if (!width) {
missingValues.push("width");
}
if (missingValues.length > 0) {
throw new Error(
`Next Image Optimization requires ${missingValues.join(
", "
)} to be provided. Make sure you pass them as props to the \`next/image\` component. Received: ${JSON.stringify(
{
src,
width,
quality
}
)}`
);
}
const url = new URL(src, window.location.href);
if (!url.searchParams.has("w") && !url.searchParams.has("q")) {
url.searchParams.set("w", width.toString());
url.searchParams.set("q", quality.toString());
}
if (!src.startsWith("http://") && !src.startsWith("https://")) {
return url.toString().slice(url.origin.length);
}
return url.toString();
};
exports.defaultLoader = defaultLoader;