简体   繁体   English

为什么 Firebase 部署完整的反应应用程序而不是部署构建目录文件?

[英]Why Firebase deploy's full react app instead of deploying build directory files?

So I created a react app using create-react-app toolchain.所以我使用 create-react-app 工具链创建了一个反应应用程序。 Wrote some components and ran编写了一些组件并运行

firebase init

npm run build

firebase deploy --only hosting

Now when i inspected my live app in source tab of chrome dev-tools it showed all the source files of react app including comments as it is.现在,当我在 chrome dev-tools 的源选项卡中检查我的实时应用程序时,它显示了 react 应用程序的所有源文件,包括评论。

Isn't firebase supposed to deploy only the chunks inside build directory which are optimised and minified for production? firebase 不应该只部署构建目录中针对生产进行了优化和缩小的块吗?

I ran Network test to see what kind of files are being fetched and amazingly it fetches only the chunks inside build directory.我运行网络测试以查看正在获取的文件类型,令人惊讶的是它只获取了构建目录中的块。 Then how all the files of my src directory also present there in raw form?那么我的 src 目录的所有文件如何也以原始形式存在?

Now chances are maybe browser construct them from chunks.现在有可能浏览器从块中构造它们。 Then it seems a react build problem that doesn't remove comments and uglify in production build.然后它似乎是一个反应构建问题,它不会在生产构建中删除评论和丑化。

But i also analyzed the js chunks in my build directory and they don't have comments embedded.但我也分析了构建目录中的 js 块,它们没有嵌入评论。

Here is my firebase config:这是我的 firebase 配置:

{
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}


So I found the solution.所以我找到了解决方案。

And it's not related to firebase hosting.它与 firebase 托管无关。

It's react's build that needs to be configured to solve this problem.需要配置 react 的构建来解决这个问题。 Basically, We have to stop react build generating source map.基本上,我们必须停止反应生成源 map。

It looks like these source map inside build directory contains our raw js files that get deployed to firebase.看起来构建目录中的这些源 map 包含我们部署到 firebase 的原始 js 文件。

Change your react build command in package.json to将 package.json 中的反应构建命令更改为


"build": "GENERATE_SOURCEMAP=false react-scripts build",

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

相关问题 未找到具有提供的路径的文件:build. 不会上传任何工件。 - Github 将 React 应用程序部署到 Firebase 的操作 - No files were found with the provided path: build. No artifacts will be uploaded. - Github Action for deploying React App to Firebase 为什么create-react-app的build目录位于.gitignore中? - Why is create-react-app's build directory in .gitignore? 使用 npm run build 部署 React 应用程序未找到文件 - Deploying React app with npm run build not finding files 如何使用 docker 和 serve -s build 部署 React 应用程序 - How to deploy React app with docker and serve -s build React + Node + Firebase,如何部署构建文件夹? - React + Node + Firebase, how to deploy build folder? 将 React 应用程序部署到 Firebase 后出现 Git 错误 - Git error after deploying React app to Firebase 仅将构建的 React 应用程序部署到应用程序引擎 - Deploy only build react app to app engine 在 Github 页面上使用 Parcel 部署 React 应用程序 - Deploying React app with Parcel build on Github Pages Firebase Deploy 为 React 应用程序显示一个空白页面 - Firebase Deploy displays a blank page for a react app 如何正确合并和部署反应构建文件? - How to merge and deploy react build files correctly?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM