NUXT 3只有客户端渲染,而不会加载
我想仅通过NUXT 3构建客户端应用程序,就像文档所描述的那样“ rel =“ nofollow noreferrer”>在这里我已经在我的nuxt配置中添加了ssr:false
。
然后,我使用nuxi build
命令来构建应用程序,但它仍然说需要使用节点运行。
我继续运行nuxi generate 正如我通常用于静态托管所做的那样。
根据GERTATE命令的输出,我应该能够将公共文件夹部署到任何静态Web托管中。但是,当我这样做时,我只会得到一个完全白色的页面。
我尝试在没有ssr:false
的情况下运行相同的命令,这确实呈现页面,但这会导致我的JavaScript无法正常工作。
编辑:最小可重复的示例
,所以我只是follewd 这些步骤来自nuxt文档。
没有进行任何代码更改,除了编辑我的nuxt配置外,我已经运行生成
。
这就是我的nuxt配置现在的样子。
import { defineNuxtConfig } from 'nuxt'
// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
ssr: false,
})
然后,我按照评论中建议的npx服务。输出/public
,这似乎在本地效果很好。
然后,我将公共文件夹复制到我的Web服务器,但是同样的问题仍然存在,只有一个白屏可见。
也许我应该再澄清一下我的问题:就像在NUXT 2中一样,在不在服务器上运行节点进程的情况下仍然可以托管NUXT SPA吗?
现在,我只是切换到服务器渲染的应用程序,因为我看不到其他解决方案。
I want to build a client-side only application via Nuxt 3, and just as the docs describe here I've added ssr: false
to my nuxt config.
I then used the nuxi build
command to build the application, but it still says it needs to be run using node.
I proceed to run nuxi generate
as I would normally do for static hosting.
According to the output from the generate command, I should be able to just deploy the public folder to any static web hosting. However, when I do this, I just get a completely white page.
I have tried running the same commands without ssr: false
, and that does render a page, but that causes none of my javascript to work.
Edit: minimal reproducible example
So I've just follewd these steps from the nuxt docs.
Without making any code changes, except for editing my nuxt config, I've run generate
.
This is what my nuxt config looks like right now;
import { defineNuxtConfig } from 'nuxt'
// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
ssr: false,
})
I then ran npx serve .output/public
as suggested in the comments, and that seemed to work just fine locally.
I then copied the public folder to my web server, but the same issue persists, just a white screen is visible.
Maybe I should clarify my question a little more: is it still possible to host a nuxt SPA, without running a node process on the server, just as it was before in nuxt 2?
Right now I just switched to a server rendered application, as I don't see another solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用NGINX为静态生成的构建服务当前将失败,因为NGINX不支持MJS文件的MIME类型(以八位字节发送)。
要修复它,只需将“应用程序/JavaScript”作为NGINX配置中MJS文件的Mimetype。
适应您的需求的示例:
1-在项目root文件夹中创建一个名为“ nginx.conf”的文件,with with:
with inclage/etc/nginx/mime.types;”我们正在加载默认的nginx mime类型,然后使用“ application/javascript MJ”扩展该列表;
2-然后您可以在图像构建步骤中使用该文件如下(检查行2):
现在您可以部署图像。如果您还没有使用相互作用,请启用GZIP线路。
Using NGINX to serve a static generated build will fail currently, because nginx do not support the MIME type for mjs files (sended as octet-stream).
To fix it just add "application/javascript" as mimetype for mjs files in the nginx configuration.
Example to adapt to your needs:
1- Create in your project root folder a file named "nginx.conf" with:
With "include /etc/nginx/mime.types;" we are loading the default nginx mime types, and after that extending that list with "application/javascript mjs;".
2 - Then you could use that file in your image build step as follow (check the line 2):
Now you can deploy the image. Enable the gzip line if you are not using compresion already.