【问题标题】:Can I comment on firebase.json file?我可以评论 firebase.json 文件吗?
【发布时间】:2019-09-13 08:53:35
【问题描述】:

我需要注释掉 firebase.json 文件中的一些行:

例子:

"rewrites": [
      // {
      //  "source": "/blog/*", 
      //  "function": "handleBlog"
      // },
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]

在这种情况下,我想暂时禁用rewrite,但我不想删除代码。

事实是 JSON 文件不允许使用 cmets,我从 VSCode 中得到一个错误告诉我。

但是如果我将语言模式设置为JSON with Comments,VSCode 的错误就消失了。

但是这样做安全吗? Firebase 如何使用 cmets 处理 firebase.json 文件?

【问题讨论】:

  • json with cmets 不再是json。它有jsonc 文件扩展名。

标签: firebase visual-studio-code comments firebase-hosting firebase-cli


【解决方案1】:

我已经在我的firebase.jsons 中评论 JSON 有一段时间了。

{
    "hosting": {
        "headers": [
            /*{
              "source": "*.html",
              "headers": [
                {
                  "key": "Content-Security-Policy",
                  "value": "default-src 'self' ..."
                }
              ]
            },*/
        ]
    }
}

【讨论】:

  • 谢谢!我已经测试过了,到目前为止也对我有用!
【解决方案2】:

JSON 格式不支持 cmets。 JSON More info can be found here 中不允许使用 //… 或 /*…*/ 形式的注释。

firebase而言,我不熟悉,但是如果在VSCode中将Language Mode设置为JSON with Comments,你会得到JSONC文件格式,而不是JSONJSONC专门用于VSCode

除了遵循 JSON 规范的默认 JSON 模式外,VS Code 还有一个 JSON with Comments (jsonc) 模式。此模式用于 VS Code 配置文件,例如 settings.json、tasks.json 或 launch.json。

【讨论】:

    猜你喜欢
    • 2010-12-29
    • 2014-09-05
    • 1970-01-01
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    • 2011-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多