为什么在vercel上部署后,为什么在NextJS项目中没有呈现SVG
我创建了一个带有尾风CSS样式的Showcase Single Page NextJS应用程序。我将组件的背景sectionWrapper
作为svg
文件。
我已经在global.css
中使用@layer
实用程序创建了一个自定义类
@layer components {
.banner {
@apply bg-[url('../assets/banner.svg')] bg-no-repeat w-full bg-cover bg-center h-full;
}
.banner02 {
@apply bg-[url('../assets/banner02.svg')] bg-no-repeat w-full bg-cover bg-center h-full;
}
.
.
}
,并在我的index.js
中使用它们。 m通过横幅
作为道具。
.
.
.
<Sectionwrapper
title="Creative way to showcase the store"
description="The app contains two screens. The first screen list all NFTs while the second shows the details of a specific NFT."
mockupImg={assets.mockup.src}
banner="banner02"
/>
.
.
.
在sectionWrapper
组件中,它用作第一个Div中的$ {Banner}
。
import React from "react";
import assets from "../assets";
import Button from "./Button";
const Sectionwrapper = ({
title,
description,
showBtn,
banner,
mockupImg,
reverse,
}) => {
return (
<div
className={`min-h-screen flex justify-center items-center p-16 sm:p-8 ${banner} ${
reverse ? "bg-white" : "bg-primary"
}`}
>
<div
className={`flex items-center w-11/12 sm:w-full minmd:w-3/4 ${
reverse
? "flex-row-reverse md:flex-col-reverse fadeRightMini"
: "flex-row md:flex-col fadeLeftMini"
} `}
>
.
.
.
</div>
</div>
</div>
);
};
export default Sectionwrapper;
问题
SVG在当地环境中工作正常。但是,在vercel
和netlify
的部署环境中,SVG不是渲染的。它在Local主机上工作良好,但在生产中效果不佳。
在本地env
中/edz4g.jpg“ alt =“ local ” href =“ https://i.sstatic.net/al6gu.png” rel =“ nofollow noreferrer”>
更多资源
github链接在这里
vercel link/live demo 在这里
I had created a showcase single page nextJS application styled with Tailwind CSS. I am adding the background of a component SectionWrapper
as an svg
file.
I had created a custom class in global.css
using @layer
utility like this
@layer components {
.banner {
@apply bg-[url('../assets/banner.svg')] bg-no-repeat w-full bg-cover bg-center h-full;
}
.banner02 {
@apply bg-[url('../assets/banner02.svg')] bg-no-repeat w-full bg-cover bg-center h-full;
}
.
.
}
And using them in my index.js
like this where I'm passing banner
as props.
.
.
.
<Sectionwrapper
title="Creative way to showcase the store"
description="The app contains two screens. The first screen list all NFTs while the second shows the details of a specific NFT."
mockupImg={assets.mockup.src}
banner="banner02"
/>
.
.
.
And in sectionWrapper
component, it is used as ${banner}
in the first div.
import React from "react";
import assets from "../assets";
import Button from "./Button";
const Sectionwrapper = ({
title,
description,
showBtn,
banner,
mockupImg,
reverse,
}) => {
return (
<div
className={`min-h-screen flex justify-center items-center p-16 sm:p-8 ${banner} ${
reverse ? "bg-white" : "bg-primary"
}`}
>
<div
className={`flex items-center w-11/12 sm:w-full minmd:w-3/4 ${
reverse
? "flex-row-reverse md:flex-col-reverse fadeRightMini"
: "flex-row md:flex-col fadeLeftMini"
} `}
>
.
.
.
</div>
</div>
</div>
);
};
export default Sectionwrapper;
ISsue
The SVGs are working fine in the local environment. But on the deployed environment of Vercel
and Netlify
, the SVG is not rendering. It is working fine in localhost but not in production.
in local env
on vercel/netlify
More resources
Github link here
Vercel link/Live Demo here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将svgs移至
public
文件夹,并在tailwind.config.js
中更新THIER路径到我对我有效。
Moving the SVGs to the
public
folder and updating thier path intailwind.config.js
to thisworks for me.