【问题标题】:Nuxt not creating dist directoryNuxt 不创建 dist 目录
【发布时间】:2021-12-02 15:48:31
【问题描述】:

我使用docker-compose 构建和运行 SSR Nuxt.JS 应用程序。 Web 服务器是nginx

我不能使用 nginx 反向代理来运行这个应用程序,因为目录dist 不是在/app/ 中创建的。这是我的Dockerfile

FROM node:14.17.0-alpine
WORKDIR /app
COPY . /app
RUN apk add python make g++
RUN yarn install
RUN yarn build
ENV HOST 0.0.0.0
ENV PORT 3000
ENV NODE_ENV production
EXPOSE 3000
CMD [ "yarn", "start" ]

它不起作用。但是如果我在我的 docker 主机路径 /home/path/project-1/ 中运行这个命令(路径 Nuxt.JS 文件存在):

yarn start

我可以通过以下方式暂时查看应用程序:

http://ip:3000

我搜索并尝试了一些解决方案,但都没有奏效(很遗憾)。

这是我在终端中运行yarn start 时的日志:

yarn run v1.22.11
$ nuxt start
ℹ [HPM] Proxy created: /api/  -> https://api.site.com/api
ℹ [HPM] Proxy rewrite rule created: "^/api/" ~> ""

   ╭───────────────────────────────────────────╮
   │                                           │
   │   Nuxt.js @ v2.14.3                       │
   │                                           │
   │   ▸ Environment: production               │
   │   ▸ Rendering:   server-side              │
   │   ▸ Target:      server                   │
   │                                           │
   │   Memory usage: 32.7 MB (RSS: 105 MB)     │
   │                                           │
   │   Listening: http://ip:3000/   │
   │                                           │
   ╰───────────────────────────────────────────╯

跑步有什么问题?

我无法将其代理传递给 nginx 的原因是没有文档根目录。如果我在root 指令的开头使用#,我在nginx 中使用此错误:

2021/10/14 12:02:29 [error] 25#25: *180 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: my_ip, server: app.site.com, request: "GET / HTTP/1.1", host: "app.site.com"
2021/10/14 12:02:29 [error] 25#25: *181 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: my_ip, server: app.site.com, request: "GET /favicon.ico HTTP/1.1", host: "app.site.com", referrer: "https://app.

更新 1

正如kissu所说,这是nuxt.config.js中的相关块:

  target: 'server',
  server: {
    port: 3000, // default: 3000
    host: '0.0.0.0', // default: localhost
  },

【问题讨论】:

  • 这里发生了很多事情。让我们稍微缩小一下这个问题。 nuxt.config.js 中的 target 是什么?
  • 那么,当您yarn build 时会发生什么?你没有在项目的根目录看到dist 目录吗?
  • .nuxt 仅用于开发目的。对于生产,你需要有一个dist,否则它根本不会被优化。
  • 哦不,我失败了。 .nuxt 也用于server,而dist 用于static。这将使用 Nuxt3 进行标准化。同时,如果您yarn build,它将在.nuxt 中创建它,如下所示:nuxtjs.org/docs/get-started/commands#server-deployment
  • 那么,你的问题解决了吗?!

标签: node.js docker nginx nuxt.js


【解决方案1】:

使用yarn build 和定位/app/.nuxt 解决了这个问题。

【讨论】:

    猜你喜欢
    • 2021-01-12
    • 2016-10-16
    • 2019-04-19
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 2014-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多