NUXT 3只有客户端渲染,而不会加载

发布于 2025-02-10 09:46:23 字数 1407 浏览 1 评论 0原文

我想仅通过NUXT 3构建客户端应用程序,就像文档所描述的那样“ rel =“ nofollow noreferrer”>在这里我已经在我的nuxt配置中添加了ssr:false

然后,我使用nuxi build命令来构建应用程序,但它仍然说需要使用节点运行。 “来自nuxi

我继续运行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.Output from nuxi build

I proceed to run nuxi generate as I would normally do for static hosting.
Output from nuxi generate

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 技术交流群。

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

发布评论

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

评论(1

多彩岁月 2025-02-17 09:46:23

使用NGINX为静态生成的构建服务当前将失败,因为NGINX不支持MJS文件的MIME类型(以八位字节发送)。

要修复它,只需将“应用程序/JavaScript”作为NGINX配置中MJS文件的Mimetype。

适应您的需求的示例:

1-在项目root文件夹中创建一个名为“ nginx.conf”的文件,with with:

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    types 
    {
        application/javascript mjs;
    }
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

with inclage/etc/nginx/mime.types;”我们正在加载默认的nginx mime类型,然后使用“ application/javascript MJ”扩展该列表;

2-然后您可以在图像构建步骤中使用该文件如下(检查行2):

FROM nginx:alpine
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY .output/public /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

现在您可以部署图像。如果您还没有使用相互作用,请启用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:

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    types 
    {
        application/javascript mjs;
    }
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

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):

FROM nginx:alpine
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY .output/public /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Now you can deploy the image. Enable the gzip line if you are not using compresion already.

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