简体   繁体   English

使用node.js和react.js客户端启动Firebase函数项目

[英]Start a firebase function project with node.js and react.js client

I am developing an application with node.js and express.js hosted on firebase using firebase functions , and development in typescript. 我正在使用firebase functions使用在firebase上托管的node.jsexpress.js开发应用程序,并在Typescript中进行开发。 I would like to use react.js as client side framework. 我想使用react.js作为客户端框架。 I set up node + express + firebase using: 我使用以下命令设置node + express + firebase

firebase init hosting
firebase init functions

However, there is no obvious way to set up react front end framework using create-react-app ... given the current project setup. 但是,在当前项目设置下,没有明显的方法可以使用create-react-app ...来设置react前端框架。 In particular, create-react-app seem to create its own node_module and index.js . 特别是, create-react-app似乎会创建自己的node_module和index.js I found this: https://medium.freecodecamp.org/how-to-make-create-react-app-work-with-a-node-backend-api-7c5c48acb1b0 我发现了这个: https//medium.freecodecamp.org/how-to-make-create-react-app-work-with-a-node-backend-api-7c5c48acb1b0

It is a bit ad-hoc. 这是临时的。 In particular, it is launching a dev server using yarn , but I am using firebase serve ... , and would like to keep it that way. 特别是,它正在使用yarn启动一个开发服务器,但是我正在使用firebase serve ... ,并希望保持这种状态。 Do these different frameworks play together at all? 这些不同的框架是否一起发挥作用? #webDev #webDev

You can definitely use React and Firebase together, but merging the complex templates generated by starter kits for each may be more trouble than it's worth. 您绝对可以一起使用React和Firebase,但是将入门工具包为每个工具包生成的复杂模板合并起来,可能会遇到麻烦,而不是值得的。

You will likely need to pick which generated template gives you the most value (whether it be from firebase init hosting or create-react-app ) and then work on standing up items from the non-chosen ones piece by piece. 您可能需要选择哪个生成的模板为您提供最大的价值(无论是从firebase init hosting还是create-react-app ),然后逐一处理未选择的项目。

If you really want to use firebase serve you will be losing hot-reload and other development time benefits that create-react-app provides, as firebase serve internally uses superstatic ( repo ) which is a dev server for hosting static files. 如果您真的想使用firebase serve那么您将失去create-react-app提供的热重载和其他开发时间优势,因为firebase serve内部使用superstatic静态( repo ),后者是用于托管静态文件的开发服务器。

You can use React with such a setup by npm install --save react react-dom and then using React as normal, but it's very likely that you will want a toolchain between your source and the static files that firebase serve serves (given your use of the typescript tag, I'm assuming you at least need to transpile .ts to .js), and you will then need to set that up on your own if you simply want to use firebase-serve . 您可以通过npm install --save react react-dom来使用React进行这样的设置,然后像往常一样使用React,但是很可能您会希望在源和firebase serve的静态文件之间建立工具链(考虑到您的使用)在的typescript标签,我假设你至少需要transpile .TS到.js文件),然后你需要设置了你自己,如果你只是想用firebase-serve

In my opinion, the dev toolchain that you get through create-react-app will provide more immediate value for your specific situation than wanting to stick with firebase serve . 我认为,通过create-react-app获得的开发工具链将为您的特定情况提供更多的即时价值,而不是想要坚持使用firebase serve Is there any specific reason you feel glued to firebase serve ? 您是否觉得粘在firebase serve有什么具体原因吗?

(Not using firebase serve in no way causes issues running firebase deploy --only hosting later when you want to deploy to firebase hosting, as long as your hosting config points to the directory where npm run build outputs your built files.) (不使用firebase serve绝不会引起运行firebase deploy --only hosting问题-仅在稍后要部署到firebase deploy --only hosting时托管,只要您的托管配置指向npm run build输出您生成的文件的目录。)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM