English 中文(简体)
如何出口下游的静态图像?
原标题:How to export static images on Nextjs?

当我要出口我的下几秒时,我说,我不能在固定网站上输出我的图像。

Error: Image Optimization using Next.js default loader is not compatible with next export. Possible solutions: - Use next start to run a server, which includes the Image Optimization API. - Use any provider which supports Image Optimization (like Vercel). - Configure a third-party loader in next.config.js. - Use the loader prop for next/image.

我怎么能这样做呢?

难道我可以简单地告诉它,让形象静态化吗? 我不想通过其他在线图像装载器。

最佳回答

你们需要在下台安装一个定制图像载体。 j)

next.config.js 文档中,将这一财产添加到出口中:

images: {
  loader: "custom"
}

出口:

function imageLoader({ src }) {
  return `/images/${src}`; // REPLACE WITH YOUR IMAGE DIRECTORY
}

module.exports = imageLoader;

For each Image component, set the loader prop manually:

const imageLoader = require("PATH TO loader.js");

<Image loader={imageLoader} />
问题回答

我会补充一下Skara9的回答,因为它对我的工作不多。 我发现thread。 这只是围绕下司法学院图像部分进行的总结,对我来说,工作是毫无道理的。

// components/Image.js
import NextImage from "next/image";

// opt-out of image optimization, no-op
const customLoader = ({ src }) => {
  return src
}

export default function Image(props) {
  return (
    <NextImage
      {...props}
      loader={customLoader}
    />
  );
}

确保您的进口发生变化,并更新<编码>。

import Image from  ../components/Image.js 

The most simple solution now is to just opt-out of next Image optimization. This was no issue for my project. You can do this by adding this to your next.config.js:

output:  export ,
images: {
    unoptimized: true,
}

或者,你可以使用不需要服务器运行时间的定制装货机,我获得建议,因为:

  1. It s probably easier to just use a supported cloud Image loader like cloudinary.
  2. You could just as easy use Next s built-in image optimiser which you can launch with next start.

然而,如果你真想使用一种习俗预处理器和装载器,你可使用。 https://www.npmjs.com/ Package/next-image-export-optimizer 如先前的答复所述。

对于那些自2023年以来希望出口最佳图像的人来说,你们可以在这里读到更多的东西!

https://next-export-optimize-images.vercel.app/docs/comparison#next-image-export-optimizer” rel=“nofollow noreferer”>https://next-export-optimize-images.vercel.app/docs/comparison#next-image-export-optimizer

安装

yarn add -D next-export-optimize-images

and

const withExportImages = require(  "next-export-optimize-images");
module.exports = withExportImages({...baseConfig, output: "export"})

然后改变建筑设计

{
-  "build": "next build",
+  "build": "next build && next-export-optimize-images",
}

你们都需要这样做。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签