简体   繁体   English

Nuxt3 - 在 GitHub 页面上找不到“_nuxt”目录 (404)

[英]Nuxt3 - `_nuxt`-directory not found (404) on GitHub Pages

(I know it might sound similar to missing js files from _nuxt folder , but unfortunately, I was not able to understand the answer from there) (我知道这听起来可能类似于缺少 _nuxt 文件夹中的 js 文件,但不幸的是,我无法从那里理解答案)

When I deploy my dist -folder to GitHub Pages, it contains当我将dist文件夹部署到 GitHub 页面时,它包含

dist 
| _nuxt
  | css/main.css
  | entry.*******.css
  | entry-*******.mjs
  | index-*******.mjs
  | history-********.mjs
  | header-********.mjs
  | ... some other mjs-files
| css/main.css
| index.html
| history.html
| ... some other HTML-files

The HTML-pages are served, perfectly fine, and in the <head> -section, they want to load the modules ( .mjs -files).提供 HTML 页面,非常好,并且在<head> -部分,他们想要加载模块( .mjs -文件)。 All of these requests, unfortunately, fail with a 404:不幸的是,所有这些请求都以 404 失败:

Chrome 控制台错误 I Chrome 控制台错误二

Why do the requests to the _nuxt -folder fail, while / and /css requests go through?为什么对_nuxt文件夹的请求失败,而//css通过 go 请求?


Edit: Just seen that in VS Code, this folder is just marked as a symlink to the .output/public -folder (generated by nuxi generate ):编辑:刚刚在 VS Code 中看到,这个文件夹只是被标记为.output/public -文件夹的符号链接(由nuxi generate ):

在此处输入图像描述 . .

Might that be the issue?可能是这个问题吗? But appears that it contains the files, anyway:但无论如何,它似乎包含文件:

在此处输入图像描述


Edit II: I cannot run npm run start for local tests ( node.output/server/index.mjs ), because the .output/server folder is empty, as can be seen on the image:编辑二:我无法运行npm run start进行本地测试( node.output/server/index.mjs ),因为.output/server文件夹是空的,如图所示:

在此处输入图像描述

When running the folder in Live Server (VS Code extension), the errors return:在 Live Server(VS Code 扩展)中运行文件夹时,错误返回:

在此处输入图像描述


Actually, after downloading the generated .tar -file (the artifact that is generated automatically by GitHub Actions for deployment) does not include the _nuxt -directory, but just the static HTML-files and css -directory as well as an assets dir with assets/css/main.css -file in it. Actually, after downloading the generated .tar -file (the artifact that is generated automatically by GitHub Actions for deployment) does not include the _nuxt -directory, but just the static HTML-files and css -directory as well as an assets dir with assets/css/main.css的文件。 Why is the _nuxt -directory ignored by the GitHub Action?为什么_nuxt操作会忽略 _nuxt 目录?

As told here正如这里所说

It is now possible to completely bypass Jekyll processing on GitHub Pages by creating a file named.nojekyll in the root of your pages repo and pushing it to GitHub.现在可以完全绕过 GitHub 页面上的 Jekyll 处理,方法是在页面存储库的根目录中创建一个名为.nojekyll 的文件并将其推送到 GitHub。 This should only be necessary if your site uses files or directories that start with underscores since Jekyll considers these to be special resources and does not copy them to the final site.仅当您的站点使用以下划线开头的文件或目录时才需要这样做,因为 Jekyll 认为这些是特殊资源并且不会将它们复制到最终站点。

This might answer the question, since the _nuxt -directory is prefixed with an underscore, it will be ignored by Jekyll builds.这可能会回答这个问题,因为_nuxt以下划线为前缀,Jekyll 构建将忽略它。 This means, adding a .nojekyll -file, should solve the issue, according to GitHub Blog .这意味着,根据GitHub 博客,添加.nojekyll文件应该可以解决问题。

The .nojekyll -file will obviously have to be placed in the directory that is deployed, in my case, since I am only deploying dist , it needed to be in nuxt's public -folder to be included in the dist -directory. .nojekyll文件显然必须放在部署的目录中,在我的情况下,因为我只部署dist ,它需要位于 nuxt 的public文件夹中才能包含在dist目录中。

Add .nojekyll empty file to the public folder and run npm run generate ..nojekyll空文件添加到public文件夹并运行npm run generate

Add the below snippet to defineNuxtConfig config将以下代码段添加到defineNuxtConfig配置

  target: 'static',
  router: {
    base: '/ repo name /', //eg:- /crstnmac.github.io/
  },

Use the below script to deploy your nuxt website to github pages使用以下脚本将您的 nuxt 网站部署到 github 页面

"deploy": "push-dir --dir=dist --branch=gh-pages --cleanup"

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

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