简体   繁体   English

如何使用 NextJS 托管 static js 文件

[英]How to host static js files with NextJS

I am trying to host static js and css files with NextJS.我正在尝试使用 NextJS 托管 static js 和 ZC7A62​​8CBA22E28EB17B5F5C6AE2A266AZ 文件。

What I have done so far is that I have created a react app using create-react-app, created an App component, then run the npm run build command, upon which a few static js and css files were created.到目前为止,我所做的是我使用 create-react-app 创建了一个反应应用程序,创建了一个应用程序组件,然后运行 ​​npm 运行构建命令,在此基础上创建了一些 static js 和 ZC7A62​​8CBA22AE28EB17B5F5C6 文件。 I then hosted those files using firebase hosting, such that these static js and css files could be accessed from a plain index.html file. I then hosted those files using firebase hosting, such that these static js and ZC7A62​​8CBA22E28EB17B5F5C6AE2A266AZ files could be accessed from a plain index.html file. By doing this, I was able to embed react components into a plain.html file using a script tag, a link tag and a div.通过这样做,我能够使用脚本标签、链接标签和 div 将 react 组件嵌入到 plain.html 文件中。 All i needed was for the link tag to source the static css file hosted by firebase and the script tag to source the static js file hosted by firebase. All i needed was for the link tag to source the static ZC7A62​​8CBA22E28EB17B5F5C6AE2A266AZ file hosted by firebase and the script tag to source the static js file hosted by firebase.

What I want to do however, is to take these two static files that were "imported" via the script and link tags and host them in a different project, where I have all my other code.然而,我想做的是获取通过脚本和链接标签“导入”的这两个 static 文件,并将它们托管在不同的项目中,在那里我拥有所有其他代码。 I want to add them to a next.js project and host them with the help of firebase.我想将它们添加到 next.js 项目中,并在 firebase 的帮助下托管它们。 What I have tried is to add the static files I want to have hosted into the _next folder and then hosted the project.我尝试将我想要托管的 static 文件添加到 _next 文件夹中,然后托管项目。

I cannot find the static files however and I certainly cannot access them via script or link tags.但是,我找不到 static 文件,当然也无法通过脚本或链接标签访问它们。 Any ideas on how I should host these static js and css files?关于如何托管这些 static js 和 ZC7A62​​8CBA22E28EB17B5F5C6AE2A266AZ 文件的任何想法?

Here is a method utilize a cloud delivery network and just use the html tags and include the src if you have just 1 or 2 static files这是一种利用云交付网络的方法,只需使用 html 标记,如果您只有 1 或 2 个 static 文件,请包含 src

Here is the CDN i utilize its open source and free:D https://cloudinary.com/这是我利用其开源和免费的 CDN:D https://cloudinary.com/

 <img alt="close-menu-icon" src="https://res.cloudinary.com/dxgqvvg0z/image/upload/v1658891864/Personal%20Portfolio%202023/NavBar/cross_aefzpg.svg"/>

and for your case https://nextjs.org/docs/api-reference/next/image对于您的情况https://nextjs.org/docs/api-reference/next/image

import Image from 'next/image';

<Image
alt="close-menu-icon"
 src="https://res.cloudinary.com/dxgqvvg0z/image/upload/v1658891864/Personal%20Portfolio%202023/NavBar/cross_aefzpg.svg"/
/>

Or或者

import Image from 'next/image';

//Example for an Image inside a project dir
<Image src="./public" />
<Image src="./src/assets/images"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM