【问题标题】:Problems with deploy Nuxt.js project on GitHub Pages在 GitHub Pages 上部署 Nuxt.js 项目的问题
【发布时间】:2019-04-11 13:47:29
【问题描述】:

我有一个项目: https://github.com/merrymaker14/vuegl

我决定上传到 GitHub Pages: https://merrymaker14.github.io/vuegl

但他并没有正常浏览这些页面,尽管他似乎已经设置了所有内容。为什么? 我都是按照官方文档做的。

nuxt.config.js:


/* nuxt.config.js */
// only add `router.base = '/<repository-name>/'` if `DEPLOY_ENV` is `GH_PAGES`
const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ? {
  router: {
    base: '/vuegl/'
  }
} : {}

export default {
  mode: 'universal',

  /*
  ** Headers of the page
  */
  head: {
    title: pkg.name,
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: pkg.description }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },

  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#fff' },

  ...routerBase,

  router: {
     middleware: 'pages',
     //base: '/examples/vuegl/'
  },

  /*
  ** Global CSS
  */
  css: [
  ],

  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
  ],

  /*
  ** Nuxt.js modules
  */
  modules: [
  ],

  /*
  ** Build configuration
  */
  build: {
    /*
    ** You can extend webpack config here
    */
    extend(config, ctx) {
    }
  }
}```

【问题讨论】:

标签: nuxt.js


【解决方案1】:

我遇到了同样的问题,这就是我要解决的问题。

  1. 添加到nuxt.config.js:
  // Allows page refresh to work on github pages
  generate: {
    fallback: "404.html"
  },
  1. 将空白文件 .nojekyll 添加到 static/ 目录(防止 github 将其构建为 Jekyll 站点

  2. 部署时您需要执行gh-pages -d dist -t true因为默认部署会忽略以'.'开头的文件

为什么会这样

上述解决方案解决了几个问题。

  1. 添加 fallback: "404.html",这允许 SPA 的(单页应用程序)在 Github 页面上工作。

    1. example.github.io/my-nuxt-app/some/page 这样的任何路由都会重定向到自定义的404.html 文件,这将保持SPA 加载。 more info here
  2. .nojekyll 阻止 github 将其构建为 Jekyll 站点,如果 gh-pages 站点具有 /pages 目录,Github 会自动认为它是 Jekyll 站点

  3. gh-pages -d dist -t true 是必需的,以便 .nojekyll 文件实际部署到 Github Pages,因为默认情况下,gh-pages 命令会忽略以 . 开头的文件

【讨论】:

  • 嗨,本!谢谢你。你能解释一下它为什么起作用吗?它在同样的情况下帮助了我。我不认为 .nojekyll 是主要问题?
  • 添加了更多解释,这个解决方案实际上解决了3个问题......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-05
  • 1970-01-01
  • 2021-08-12
  • 2018-10-05
  • 2018-05-16
  • 1970-01-01
  • 2022-01-11
相关资源
最近更新 更多