为什么在vercel上部署后,为什么在NextJS项目中没有呈现SVG

发布于 2025-02-12 06:07:23 字数 2362 浏览 1 评论 0原文

我创建了一个带有尾风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在当地环境中工作正常。但是,在vercelnetlify的部署环境中,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

local

on vercel/netlify

vercel

More resources

Github link here

Vercel link/Live Demo here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远昼 2025-02-19 06:07:35

将svgs移至public文件夹,并在tailwind.config.js中更新THIER路径到

@layer components {
  .banner {
    @apply bg-[url('/banner.svg')] bg-no-repeat w-full bg-cover bg-center h-full;
  }

  .banner02 {
    @apply bg-[url('/banner02.svg')] bg-no-repeat w-full bg-cover bg-center h-full;
  }
  .
  .
}

我对我有效。

Moving the SVGs to the public folder and updating thier path in tailwind.config.js to this

@layer components {
  .banner {
    @apply bg-[url('/banner.svg')] bg-no-repeat w-full bg-cover bg-center h-full;
  }

  .banner02 {
    @apply bg-[url('/banner02.svg')] bg-no-repeat w-full bg-cover bg-center h-full;
  }
  .
  .
}

works for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文