【问题标题】:Firebase deploy, ignore all files but public folderFirebase 部署,忽略除公用文件夹以外的所有文件
【发布时间】:2017-02-17 13:45:15
【问题描述】:

我正在尝试清理我到 Firebase 的部署过程,并且在将文件部署到主机时需要忽略除我的 /dist aka 公用文件夹之外的所有文件。我相信它可以通过firebase.json 中的ignore 设置来完成,但除了手动指定所有文件之外,我不确定如何实现它。

示例.json:

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "dist",
    "ignore": [
      // ignore all other files besides dist folder here
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

【问题讨论】:

    标签: firebase firebase-hosting firebase-tools


    【解决方案1】:

    使用全局 **ignore any file or folder in an arbitrary sub-directory

    然后您可以使用!dist 取消忽略您的dist 文件夹

    所以你的firebase.json 文件看起来像:

    {
        "database": {
            "rules": "database.rules.json"
            },
            "hosting": {
                "public": "dist",
                "ignore": [
                    "**",
                    "!dist/**"
                ],
                "rewrites": [{
                    "source": "**",
                    "destination": "/index.html"
                }
            ]
        }
    }
    

    对于较新版本的 Firebase:

    新版本的 firebase 似乎不允许上述方法,因此只需定义应忽略的文件夹:

    {
        "database": {
            "rules": "database.rules.json"
            },
            "hosting": {
                "public": "dist",
                "ignore": [
                    "**/node_modules/**",
                    "**/src/**",
                    "**/public/**"
                ],
                "rewrites": [{
                    "source": "**",
                    "destination": "/index.html"
                }
            ]
        }
    }
    

    您可以使用 Firebase 控制台检查已部署的文件数量:

    1. 打开您的 Firebase 项目的托管页面并记下文件的数量。
    2. 运行命令$ tree dist/(因为在本例中dist/ 是我们在Firebase 主机上提供的文件夹)并记下构建文件夹中的文件数量。

    这些文件的数量应该大致相同。

    【讨论】:

    • 由于某种原因,这不适用于 firebase 版本 3.15.0
    【解决方案2】:

    ignore 属性指定部署时要忽略的文件。它可以采用 glob 模式,与 Git 处理 .gitignore 的方式相同。

    以下是要忽略的文件的默认值:

    "hosting": {
      // ...
    
      "ignore": [
        "firebase.json",  // the Firebase configuration file (this file)
        "**/.*",  // files with a leading period should be hidden from the system
        "**/node_modules/**",  // contains dependencies used to create your site but not run it
    
        "**/someOtherFolder/**"  // this is will exclude the folder with the name entered
        "**someOtherFile**" // this will exclude that particular file
      ]
    }
    

    【讨论】:

      【解决方案3】:

      !(pattern) 匹配与所提供的任何模式不匹配的任何内容。

      *只匹配公共目录根目录下的文件和文件夹

      {
        "hosting": {
          "public": "dist",
          "ignore": ["**, !*"],
          "rewrites": [
            {
              "source": "**",
              "destination": "/index.html"
            }
          ]
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2011-10-23
        • 2018-09-17
        • 2010-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-26
        • 2011-06-04
        • 2017-09-02
        相关资源
        最近更新 更多