【问题标题】:next.js deployed using now missing styles, styles.css 404 responsenext.js 使用现在缺少的样式、styles.css 404 响应部署
【发布时间】:2019-04-19 02:26:13
【问题描述】:

我正在使用 next 为学校项目构建一个简单的站点,并且我设法使用 now 部署 next.js 应用程序,但没有应用任何样式。一切都很好,在本地主机上工作(看起来)很棒,但不是在线 (https://spa-ot24z7ugt.now.sh)。

我想这与 now.json 文件有关,但他们的文档使它看起来一切都可以开箱即用,除了样式之外,这确实是真的。我查看了文档,找不到任何东西,我想知道是否有人有使用 now 和 next.js 的经验。

我的 now.json 文件:

```{
  "version": 2,
  "builds": [
    { "src": "next.config.js", "use": "@now/next" }
  ]
}```

链接到已部署的站点: https://spa-ot24z7ugt.now.sh

我正在使用“next/head”中的 Head 来生成静态 CSS 文件的链接。

【问题讨论】:

    标签: css devops next.js


    【解决方案1】:

    对我来说,“_”目录被忽略了。

    以 _ 为前缀的文件(如 _next、_css、_js)对于 jekyll 来说是特殊的。您可以通过创建一个 .nojekyll 在 gh-pages repo 的根目录中创建文件并将其推送到 GitHub。

    参考:https://github.blog/2009-12-29-bypassing-jekyll-on-github-pages/

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,我的解决方法是将 style.css 包含为静态构建:

      {
          "version": 2,
          "name": "wp-nextjs",
          "public": true,
          "builds": [
              { "src": "package.json", "use": "@now/next" },
              { "src": "static/css/style.css", "use": "@now/static" }
          ]
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-04-12
        • 1970-01-01
        • 2019-04-06
        • 2022-09-30
        • 1970-01-01
        • 1970-01-01
        • 2020-11-22
        • 1970-01-01
        相关资源
        最近更新 更多